C++常见错误详解Visual C++ Error Messages
This page contains a listing of "difficult to diagnose" error messages and possible fixes. I haven't taught a programming class that uses Visual C++ in several years so this list is probably out of date by now. It was valid for Microsoft Visual C++ version 6.0 service pack 3.
--------------------------------------------------------------------------------
C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information
This error results from leaving off the parentheses immediately following the function name in a function header. To correct the error simply add () to the end of the function name.
--------------------------------------------------------------------------------
C1010: unexpected end of file while looking for precompiled header directive
If your project is an MFC AppWizard created project then this error results from not #including StdAfx.h as the first #include statement (before any other #includes, data declarations, or executable program code).
--------------------------------------------------------------------------------
C1083: Cannot open precompiled header file: 'Debug/.pch': No such file or directory
This error results from a missing file - the compiled version of StdAfx.cpp. Visual C++ does a poor job of keeping track of this file and frequently "forgets" how to build it. This problem often occurs after restoring a saved workspace from diskette without the Debug directory. To fix the error select StdAfx.cpp from the workspace file list them choose Compile from the Build menu. If that doesn't work the go to Project -> Settings, select the C/C++ tab, and click the radio button labeled Create Precompiled Headers.
--------------------------------------------------------------------------------
C2001: newline in constant
This error is usually caused by a string or character constant that is missing its closing ' or " symbol.
--------------------------------------------------------------------------------
C2065: '' : undeclared identifier
If this error occurs in one of your member functions then it is generally the result of forgetting the class scope operator in front of the function name in your .cpp file.
--------------------------------------------------------------------------------
C2143: syntax error : missing ';' before 'PCH creation point'
Check each of the #include files to ensure that the closing brace of each class declaration is followed by a semicolon.
--------------------------------------------------------------------------------
C2143: syntax error : missing ';' before '*'
If this error is followed by two C2501 errors then the problem is an undeclared class name within a pointer declaration.
For example, the declaration:
CClass *pObject;
will generate the above error message followed by a C2501 error message for 'CClass' and another C2501 message for 'pObject'. The problem is that the compiler isn't recognizing CClass as a valid class/type name. To correct the problem add a #include of the file containing the declaration of CClass (e.g., #include CClass.h)
--------------------------------------------------------------------------------
C2447: missing function header (old-style formal list?)
This error usually results from a missing { or use of a ; instead of a { following the parameter list of a function header.
--------------------------------------------------------------------------------
C2511: '' : overloaded member function not found in ''
This error results from a mismatch in the parameter list of a member function declaration (.h file) and definition (.ccp file). Check the forward declaration of the function in the .h file and its definition in the .cpp file and ensure that the number of parameters and the type of each parameter match exactly.
--------------------------------------------------------------------------------
C2512: '' : no appropriate default constructor available
This error usually occurs when you implement the constructor function of a derived class and forget to include parameter passing to the base class constructor function. For example assume that CDerived is derived from CBase and that the CBase constructor function requires one parameter (e.g., int A). If you define the CDerived constructor function as:
CDerived::CDerived(int A, int B) { ... }
the compiler will issue the above error message on the line containing the function header of CDerived::CDerived() because you haven't provided instructions for routing the parameter A to CBase::CBase(). Because you didn't provide instructions the compiler assumes that CBase::CBase() requires no arguments and it complains because no version of CBase::CBase() has been defined that accepts zero arguments.
If you intended to provide a version of CBase::CBase() that requires no arguments then the error message indicates that you forgot to declare that function in your base class declaration (e.g., in CBase.h).
If CBase::CBase() does require one or more arguments then you must correct the problem by including explicit instructions for passing parameters from the derived class constructor function to the base class constructor function. The correction for the example above is:
CDerived::CDerived(int A, int B) : CBase(A) { ... }
--------------------------------------------------------------------------------
C2556: '' : overloaded functions only differ by return type
C2371: '' : redefinition; different basic types
These errors usually result from a mismatch of function type between a .h and .cpp file. Check the forward declaration of the function in the .h file and its definition in the .cpp file and make the function return type identical in both files.
--------------------------------------------------------------------------------
C2601: '' : local function definitions are illegal
This error results from defining one function inside the body of another function. It usually means that you omitted one or more } symbols in the function just before the function named in the error message.
--------------------------------------------------------------------------------
C2653: '' : is not a class or namespace name
This error usually results from not having #include "StdAfx.h" as the first #include statement in your class.cpp file. It can also occur if your class definition is in a .h file and you forget to #include that .h file in another file that refers to the class name.
--------------------------------------------------------------------------------
C2661: '::' : no overloaded function takes n parameters
This error indicates a mismatch between the parameters used in a function call (e.g., from main.cpp) and the declaration of the function. The function call is passing n parameters and there is no function declaration that uses that number of parameters.
--------------------------------------------------------------------------------
LNK1104: Cannot open file nafxcwd.lib
This error sometimes occurs when a project uses a class from the MFC but the project settings don't explicitly tell the link editor to look in the MFC libraries.
Go to Project --> Settings (Build --> Settings in Visual C++ 4.0). On the General tab check the box that says "Use MFC in a Shared DLL".
--------------------------------------------------------------------------------
LNK1168: cannot open Debug\.exe for writing
This error occurs when the link editor attempts to write to a .exe file that is currently in use. The .exe file of an executing program is write protected until the program is terminated. Look at the status bar at the bottom of your screen and find the icon representing your executable application. Open the application and exit from it. Then select Build.
--------------------------------------------------------------------------------
LNK2001: unresolved external symbol __endthreadex
LNK2001: unresolved external symbol __beginthreadex
These errors result from using an MFC object or function without telling the link editor to search the MFC libraries.
Go to Project --> Settings (Build --> Settings in Visual C++ 4.0). On the General tab check the box that says "Use MFC in a Shared DLL".
--------------------------------------------------------------------------------
LNK2001: unresolved external symbol _main
Your project doesn't contain a function called main(). The error usually results from forgeting to add main.cpp to the project workspace.
--------------------------------------------------------------------------------
.obj : error LNK2001: unresolved external symbol "public: void __thiscall ::()"
This a generic form of a LNK2001 error where .obj can be any object file in your project and ::() can be any function in any class. Substitute the specific , , , and in your message into the instructions below to diagnose and correct the problem.
An LNK2001 error means that the link editor is looking for a compiled function and can't find it. The call to the "missing function" is somewhere in .cpp. Unfortunately, double-clicking on the error message won't take you to the point in where the function is called but you can search for it with Find or Find In Files. The function the link editor can't find is a member of , its name is , and its return type is .
There are two common reasons for a LNK2001 error:
The call in .cpp doesn't match the function prototype in .h and/or the implementation in .cpp. The mismatch may be in the function name, return type, or number and/or type of parameters. Correction strategies include:
Check that the function name is spelled the same (case sensitive) in all three files (File.cpp, Class.h, and Class.cpp).
Check that the function is actually declared and defined within - perhaps you defined it as a member of a different class or perhaps you tried to call the function (in .cpp) using an object or object pointer of a different class.
Check that the number and type of parameters in the function implementation (in .cpp) matches the number and type of parameters declared in the function declaration in .h.
Check that the number and type of parameters in the function call (in .cpp) matches the number and type of parameters declared in the function header in .cpp.
The function was never declared or was declared but never defined. To see if either is the case go to the ClassView window of the Workspace view. Click the + next to and find in the list of member functions.
If is NOT in the list then it was never declared or defined - add a declaration to the class declaraion in .h and implement the function in .cpp.
If is in the list then right click on it and select Go To Definition from the pop-up menu. If you get the error message Cannot find definition (implementation) of this function then the function was declared but never defined (implemented). Implement the function to .cpp.
--------------------------------------------------------------------------------
LNK2005: already defined in .lib(.obj)
This error usually results from including a source code file multiple times. If you recognize any of the names in the message then it probably results from multiple inclusion of one of your own header files. Check to be sure that you've used #ifndef/#define/#endif properly your header files. If you don't recognize the name then it's probably multiple inclusion of a system file (e.g., afxwin.h). Make sure that you haven't explicitly included something in main.cpp that is already included in one of your own header files. Also check that you haven't #included a .cpp file where you should have #included a .h file.
- 浏览: 40408 次
- 性别:
- 来自: 广州
相关推荐
《Visual+C++精彩实例详解》是一本专注于使用Visual C++进行软件开发的实践性书籍,适合于已经掌握C++基础知识并希望深入理解Visual C++的开发者。这本书详细讲解了如何利用Visual C++ 6.0版本进行高效编程,涵盖了...
《Visual C++精彩实例详解》是一本专注于通过实例教学Visual C++编程的书籍。它旨在帮助读者深入理解和熟练掌握Visual C++这一强大的Windows应用程序开发工具。本书覆盖了多个实际应用场景,通过详细的实例代码,...
C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++编程实例详解C++...
《Visual C++游戏开发经典案例详解》这本书是针对使用Visual C++进行游戏开发的专业指南,旨在帮助读者通过实例学习和掌握C++编程语言在游戏开发中的应用。书中的内容覆盖了从基础到高级的游戏开发技术,包括图形...
《Visual C++ Redistributable Packages for Visual Studio 2013:解决DLL缺失问题的关键》 在计算机编程领域,Visual C++ Redistributable Packages for Visual Studio 是一个至关重要的组件,尤其是对于那些使用...
Visual C++ Redistributable Packages是Microsoft为Visual Studio开发的一款重要组件,主要目的是为了支持运行使用Visual C++编译器创建的依赖于特定版本MFC(Microsoft Foundation Classes)、ATL(Active Template...
在实际应用中,Visual C++串口通信技术详解可能包括了如何设置串口参数、调试通信问题、优化通信效率等方面的具体步骤和示例代码。通过深入学习和实践,开发者可以熟练掌握这一技术,实现与各类硬件设备的高效交互。
总结来说,Visual C++ Redistributable Packages for Visual Studio 2013是确保Windows平台上C++应用程序正常运行的关键组件,而"MSCVR120.dll"的缺失是许多软件安装过程中常见的问题。通过正确安装提供的...
Visual C++ Redistributable Packages for Visual Studio 2013
《Microsoft Visual C++ Redistributable for Visual Studio 2013详解》 Microsoft Visual C++ Redistributable for Visual Studio 2013(vcredist_x86.exe)是微软为开发者提供的一款重要组件,主要用于支持运行...
文件系统操作也是C++开发中的常见任务,本书会教你如何在Visual C++中读写文件,管理目录,以及使用流I/O进行更复杂的文件操作。这将使你能够处理程序的持久化存储问题。 对于需要进行图形界面编程的开发者,书中还...
资源是Visual+C++网络编程经典案例详解 pdf 由于文件过大,我就只好分拆了两份,虽然资源分有点多,但只要需要者给我鼓励下,你的资源分还是会还给你的,你也理解我们资料分享着的劳动呵。
Visual C++ 6.0 常见错误信息表
1. Visual C++ Redistributable Packages for Visual Studio 2013 2. Visual C++ Redistributable Packages for Visual Studio 2015
1. Visual C++ Redistributable Packages for Visual Studio 2013 2. Visual C++ Redistributable Packages for Visual Studio 2015
《Visual C++ Redistributable for Visual Studio 2015:关键组件与应用解析》 在计算机编程领域,尤其在Windows环境下,Visual C++ Redistributable for Visual Studio 2015是一个至关重要的组件。它不仅是开发...
在Windows操作系统中,开发C或C++程序时,可能会遇到“error: Microsoft Visual C++ 14.0 or greater is required”这样的错误信息。这个错误表明你的计算机上缺少微软的Visual C++编译器,它是Microsoft Visual ...
在"Visual C++数字图像模式识别技术详解"这个资料中,你可能会找到关于如何在Visual Studio环境中设置项目、如何导入OpenCV库、如何编写代码来实现上述步骤的详细示例。通过这些例程,你可以学习如何处理图像、提取...
描述中提到的"error: Microsoft Visual C++ 14.0 is required." 是Python在尝试安装C/C++扩展模块时常见的错误提示。这表明用户的系统中缺少用于编译Python扩展模块所需的VC++编译环境。这个问题通常发生在尝试安装...