Tag Archives: C/C++

Error: expected class name before ‘{‘ token

The error of C + + compiler is as follows:

error: expected class-name before ‘{’ token

When deriving a class, you need to confirm whether it contains the header file of the base class.

If the header file of the base class is included, an error is still reported. As mentioned above, check the header file contained in the base class header file.
For example, all the information about an error is as follows:

aarch64-himix100-linux-g++ -c ./src/base.cpp ./src/host.cpp ./src/main_test.cpp ./src/mcu.cpp ./src/uart1.cpp 
In file included from ./src/../include/main_test.h:6:0,
                 from ./src/../include/base.h:6,
                 from ./src/base.cpp:1:
./src/../include/uart1.h:10:1: error: expected class-name before ‘{’ token
 {
 ^
make: *** [main_test.o] Error 1

There are base classes in the base. H file. Uart1. H is the class to be derived. But look at all the above error information, it appears from the sixth line of base. H. Find line 6, which is the header file of the main function (test program).
Put the header file in line 6 base.cpp It’s OK.

In fact, the above situation should not appear in base. H and base.cpp The header file of the test file should not appear in.

Put the header files (such as # include & lt; pthread. H & gt;) in the corresponding header files (such as base. H).

When testing, you only need to include the base. H file to test the functions in the base.

Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +

catalog

1. Problem description 2. Cause analysis 3. Solution

1. Problem description

When running the program, the compiler reports an error:

error: cannot pass objects of non-trivially-copyable type ‘std::string {aka struct std::basic_ string}’ through ‘…’ |

2. Cause analysis

The error is displayed on this line:

printf("%c %s %lld %lld\n", p, edges, ver, edge);

Where edges is of string type.

Grammar:

const char *c_ str();c_ Str() function returns a pointer to a normal C string, the content of which is the same as that of this string string. In order to be compatible with C, there is no string type in C, so it must pass the member function C of string class object_ Str () converts a string object to a string style in C.

3. Solutions

In use, add C_ str();

printf("%c %s %lld %lld\n", p, edges.c_str(), ver, edge);

Error: transfer of control bypasses initialization of: variable XXX solution

Error: transfer of control bypasses initialization of: variable XXX

The nature of the problem, causes and Solutions

The nature of the problem

The code may skip the initialization of some variables, which makes the program access the uninitialized variables and crash.

Causes

I encountered this problem when porting the code from the vs compiling environment of windows to the G + + of Linux (actually compiling CUDA C + + code with nvcc, but the nvcc background also calls G + + to compile C / C + + part of the code). Later, it was found that in vs environment, it was just a warning, but in G + +, it was an error, so this problem must be solved.

terms of settlement

    whether the variables in the analysis code are initialized, whether the variables are declared after the goto statement in the analysis code, and if so, move the variable declaration to the front of goto .
// error
goto SomeWhere;
int var = 10;
// right
int ver = 10;
goto SomeWhere;
    analyze whether or switch statements appear in the code, because switch statements are essentially implemented with goto , so the above problems may also exist. In addition to reference 2, write the variable declaration before switch, add curly brackets to each branch of switch , or change the switch statement to if / else .
// error
switch (choice)
{
    case 1:
        // do something
        break;
    case 2: 
        // do something
}
// right
switch (choice)
{
    case 1:
    {
        // do something
        break;
    }
    case 2: 
    {
        // do something
    }
}
// or
if(choice == 1)
{
	// do something
}
else if(choice == 2)
{
	// do something
}

Compiler error message: cs1056: unexpected character handling

Error generation:
always returns an error when compiling a pre-existing program code using VS2015. strange In some added to the end of the class file some [] [] [] [], prompt Unexpected character, ‘application error.

A compilation error as shown in the title was caused by a special full-corner character in C# code. > special full-corner characters are not displayed and saved in UTF-8 format, and the compiler cannot correctly recognize such characters, resulting in compilation errors.

solution:
set the file open mode of VS 2015, make it contains a file with the Angle of all special characters use utf-8 format to open.
>
1) In Solution Explorer, select the file that needs special opening. 2) Right-click the mouse button to pop up the menu, select “Open Mode”, and use “Charp Editor with Encoding” to open.

Reproduced in: https://blog.51cto.com/studybao/2048899

Three methods of referencing DLL in Visual Studio 2015

Copy the DLL file to the directory where the executable is located
 
2. Transfer engineering attributes ->; Configure properties ->; Debugging – & gt; Change the working directory to the directory where the DLL files reside
 
3. Transfer engineering attributes ->; Configure properties ->; Debugging – & gt; Set the environment to the Path= DLL directory, for example: Path=$(SolutionDir)bin
 

Reproduced in: https://www.cnblogs.com/buyishi/p/10236780.html

Configure OpenGL development environment (vs2015)

Configuring the OpenGL development environment (VS2015)
There are a lot of configuration VS + OpenGL tutorials online, for the configuration of the super treasure of the good and bad are mixed, mainly the official website did not give a good compiled library, many need to compile their own, so for beginners, it is difficult to configure successfully.
 
The following is a blog post that explains the configuration process and the rationale behind it
http://www.it165.net/pro/html/201504/38164.html
 
For beginners, everyone wants to be able to run the example given in the super bible. Here I directly give several twists and turns, all kinds of files generated after compilation, according to the following configuration can be run in VS2015 super treasure in the example, to achieve development.
 
I. Required allocation of resources

Resource download: http://download.csdn.net/download/ax_hacker/10107105
The zip package contains two folders, CJBD5_CODE and OpenGL. The former contains the sample program, and the latter is the three files required for configuration.
 
Include
Lib
Dll
 

How do I configure the development environment, as I explained in a previous blog post
http://blog.csdn.net/ax_hacker/article/details/78140003
The following is the configuration process for OpenGL.
 
1, Copy the files in the DLL folder to C:\Windows\ Syswow64 and C:\Windows\System32
 
2. Create an empty project, add a source file, and configure the project properties
 
1) Put the include from the previous folder under the include directory

 
2) lib in the library directory

 
3) Linker ->; Input – & gt; Additional dependencies freeglutd.lib; GLTools.lib; freeglut.lib; glew32s.lib

A series of problems in configuring OpenGL development environment in vs2015

Since Windows 7, the OpenGL header file has been changed to the Windows SDK, so you can’t use it if you don’t install it.
more funny is, under the win10 vs2015 recompense Windows SDK installation failure, the typical pit themselves.
> VS05 and VC6 OpenGL headers are directly included in the development environment directory.

Okay, let’s get started.
: \Program Files (x86)\Windows Kits\8.1\Include\um\ GL C> Program Files (x86)\Windows Kits\8.1\Include\um\ GL
The downloaded from https://www.opengl.org/resources/libraries/glut/ glutdlls37beta. Zip , and will be. H in the directory. At the same time will glut32. Lib, glut. Lib respectively on the
C: \ Program Files \ Windows (x86) Kits \ 8.1 \ lib \ winv6.3 \ um \ x86 , C: \ Program Files \ Windows (x86) Kits \ 8.1 \ lib \ winv6.3 \ um \ x64 directory.
As for the DLL, as long as you have the graphics driver installed correctly, you can ignore it (if not, put it in the system directory or the directory where the current executable is located).
note: the above list I found from the vs2015 project configuration, there is a $(WindowsSDK_IncludePath) of environment variables, you can find winsdk related parameters from the inside.
So you can compile OpenGL programs normally.
If you need to rely on OpenGL extensions provided by a particular vendor, you will need to go to the vendor's website to download the development kit separately, such as Intel, Nvidia, AMD, IBM, etc.
The original address
Today debug OpenGl source program, compiled through, but a running tips, computer lost glut32. DLL files, not depressed, search under the Internet provide most of the practice are more, copying the file to download this file to C: \ WINDOWS \ system in 32, but did so after found that still doesn't work, after a long afternoon, suddenly realized that may be about my new WINDOWS 7 system, but also for loading is 64 - bit, then, Try to copy this glut32.dll to your SysWOW64 folder in C:\ Windows, and it will all be OK. Here's a special note to remind everyone who installed Windows 7 and VC ++ 6.0 to pay attention to it.
PS: When you first start to contact OpenGL, you will inevitably encounter some problems, these problems may have nothing to do with the program, just some compile environment Settings and the installation of header files, special sorting, as follows:
PS: When you first start to contact OpenGL, you will inevitably encounter some problems, these problems may have nothing to do with the program, just some compile environment Settings and the installation of header files, special sorting, as follows:
PS
(1) Copy gult32.dll, Glut. DLL to Windows system system32(if Windows 7 is a 64-bit operating system, it is in C:\ Windows SysWOW64 file)
(2) Copy gult32.lib, Glut. lib to VC lib directory
(3) Copy ULT. H to include\GL of VC
The original address
Introduction to OpenGL

C / C + + cannot open the source file directory, the header file is not imported, the solution is as follows

The two methods
Configure the various dependencies
1. Project, Properties, C/C++, Additional Includes Directory: Fill in Additional Includes Directory “add. H file folder path semicolon interval multiple
2.
3
3
3
3
3
3
3
3
3
3
3> Item, Property, Linker, Input, Additional Dependency: Fill in the name of the additional dependency library. Lib space or semicolon interval multiple
Two, the use of code directly import
Copy the required xxx.h file to the compile file
Copy the required copy of the xxx.lib library to the build


IntelliSense: unable to open source file ‘StdAfx. H’

-h /.cpp file: cannot open the source file “stdafx.h”, some methods found are not applicable, such as: set project properties ->; Configure properties ->; C/C++-> Precompiled header ->; Using (/Yu)/ creating (/Yc)/ not using precompiled headers does not work either way. Despite this error, the program was run successfully. The initialization and compilation runs seem to use different lookup paths, which is a problem when developed with a lower version of VS2005/VS2008 but opened with a higher version of VS2010. The solution is:
< wbr> < wbr> < wbr> < wbr> < wbr> < wbr> < wbr> < wbr> < wbr> < wbr> < wbr> Project Properties -& gt; Configure properties -& gt; C/C++-& gt; General – & amp; gt; Additional include directory -& gt; < strong> $(ProjectDir)< /strong> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr> < /wbr>

Solution to the problem of unable to open glaux. H in vs2013

Gl /glaux. H cannot be opened. The solution is to download or copy it in the old version and put it in the directory of VS

VC6.0 C:\Program Files\Microsoft Visual Studio\VC98\Include\GL

VS2010 C:\Program Files\Microsoft SDKS \Windows\v7.0A\Include\gl

VS2013 C:\Program Files\Microsoft SDKS \Windows\v7.1A\Include\gl

1 put the lib files in the corresponding lib folder.

2 puts the.h file in the appropriate include\gl folder.

3 puts the DLL files in the system32 folder.

If it is already copied and still not available, put the corresponding header and library files in the current directory where you wrote them.
#include “GLAUX.h”

The problem of window flash after C + + program is compiled and run

Unicorns are hiring Python engineers in 2019. > >

Problem: When you first learn C++ to write Win32 Console Application using a different compiler, the resulting window may flash and disappear.
Some compilers are very good, and there are similar solutions in the example program. For example, in DevC ++, when creating a new non-empty C++ class, return 0; Before this: system(“PAUSE”); In Visual Studio there is no flash if you follow the steps, but when we press the shortcut key F5, the result will still flash. We can do this in return 0; STD ::cin.ignore(STD ::cin.rdbuf()->; in_avail()+1); That way it will show up, not just go over it. If you just want to see the result, there’s another way, and that’s in return 0; I’m going to say while(1);
Thank you @IM Xinye for reminding me. My posture has risen. When compiling, if you press F5 directly for debugging, there will be a flash of the situation. If Ctrl +F5 is not debugging, then there will be no flash.

Reproduced in: https://my.oschina.net/u/734295/blog/160510

use cin.get () instead of system (“pause”) to avoid the flash of C + + programs

C + + compiled in a separate console program execution time, often a flash, can’t see the output results, in order to solve this problem, there are a lot of people use the system (” pause “) to suspend, but so are a lot of disadvantages, there are two reasons for
a: poor portability
2: consume resources is very big, in both Windows and Linux

Instead of using system(“pause”) to pause, you can use STD ::cin.get() or getchar()
. Why not system(“pause”)?


Let’s take a look at the flow of system(“pause”)
1: Pause your program
: Start the Shell in the sub-process
3>ind commands to execute and allocate memory for them
4: Wai>r input
5: Recluse m>y
6: End the Shell <>> 7: Continue your program>

To summarize, use STD ::cin.get() or getchar() to pause the execution of a C ++ program

PS: the original http://www.gidnetwork.com/b-61.html

Reproduced in: https://blog.51cto.com/zhanggx/1305045