Summary of common compilation errors in C++

  • 2020-04-01 23:34:49
  • OfStack

In the daily coding process will encounter a variety of compilation errors, this paper analyzes the common compilation errors. (basic compilation errors are not listed here, and are constantly updated)

1. Solution to error c101008a
This error occurs during a project upgrade, such as when the project is upgraded from vs2008 to vs2010.
Solution: right-click on the project, Clean, recompile, problem solved

2. Solution to error C2252
This error occurred when the project was upgraded from vs2008 to vs2010.
Error C2252: an explicit instantiation of a template can only occur at namespace scope
Solution: It is saying that you cannot instantiate a template inside a function or a class.Move It to outside the function or class.

3. Error C2143: grammar error: missing ";" (before "*")
This error is mainly due to a type of data not include, which may be due to misspelling of all files, or the header file name has been changed, or the header file has forgotten "; ".
Solution: check if the header file is renamed and if you forgot to end the ";"

4. Error C1010: Find the unexpected end of a file when you encounter a precompiled header. Did you forget to add "#include" stdafx.h "to the source?
Solution: add "#include" stdafx.h "to the beginning of the file where the error line is reported

5. Error C1189: WINDOWS.H already included. MFC apps must not #include < Windows. H > .
Solution: include #include < Afxwin. H > Mention the first to compile successfully.

6. Error LNK2005: _dllmain@12 already defined in dllmain.obj
Solution: you just need to put WIN32,NDEBUG,_WINDOWS,_MBCS,_USRDLL,MSGBOX_EXPORTS,_WINDLL,_AFXDLL in the project Settings
_USRDLL, delete, you can compile correctly

7. R6010 error. There are many reasons for R6010 error
1. The database is missing a view.
2. The name of a stored procedure in the database changes, and the number of parameters may also change.
3. Whether exe and DLL are mixed with different versions of CRT
4. The memory resource is not released
5. Incorrect output parameters
Bottom line: Windows attributes the types of errors it cannot locate to R6010 errors

8. Error C2361: initialization of
The error C2361: initialization of 'iter2 is skipped by' default 'label
Solution: this problem is caused by the fact that the switch is not properly initialized, so you simply need to control its scope from the position of iter2, where you can add {}.
Case study: a piece of code from a real project, simplified as follows:
  The switch (t)
  {
  Case 0:
  Int a = 0;
  Break;
  Default:
  Break;
  }
What seems to be the problem? It doesn't seem to. Please use the compiler to compile...
Huh? ! An error "error C2361: initialization of 'a' is skipped by default label". How is this possible?
A few thought, understanding explanation:
C++ convention, in block statement, the scope of the object starts from the declaration statement of the object to the end of the block statement, that is, the statement after the default label can use object a.
If the program executes by jumping from the switch to default, object a is not initialized correctly.
Making sure that objects are initialized is an important design philosophy of C++, so the compiler checks this violation very closely. For example, in the example code above, the default statement is not followed by a,
But considering that later changes to the code may be inadvertently used, so the same was blocked.
Once you understand the reason, it's easy to solve it. Just explicitly limit the scope of object a.
  The switch (t)
  {
  Case 0:
  {//added for fix problem
  Int a = 0;
  Break;
  } //added for fix problem
  Default:
  Break;
  }
In the switch... Case... For (int I = 0; ...).
Unless you block the case that defines the new variable, or choose to put your new variable before switch.

9, Link2019: unresolved external symbol' symbol' referenced in function' function'
The function is only declared if it is not implemented, or if the function in the DLL has no export

Related articles: