Three ways to troubleshoot "Fatal error C1010" error

Source: Internet
Author: User

Try to write a simple class file, but at compile time prompt error, the specific error message is as follows:

 while  for precompiled Header directive

Some solutions have been found on the Internet, with the following specific methods:

    1, in the implementation of the class CPP file header first line plus "#include" stdafx.h "".

    2 . Turn off the precompiled header file option. The steps are as follows:

Project Settings (ALT+F7), C + + TAB, category combo box precompiled Headers, not Using precompiled Headers

    3 . Create an empty project, and then move the key code files to the project catalog. Such as.

Problem cause Analysis:

First look at the error message, which says: The lookup of the precompiled header file failed. So what is the precompiled header file?

The so-called precompiled header file, that is, a project (project) used in some of the MFC standard header files (such as Windows.H, Afxwin.H) pre-compile, later when the project compiles, no longer compile this part of the header file, just use the results of precompilation. This can speed up compilation and save time. The precompiled header file is generated by compiling stdafx.cpp, named after the project name, because the precompiled header file suffix is "pch", so the resulting file is projectname.pch. The compiler uses a precompiled header file through a header file, stdafx.h. StdAfx.h This header file name can be specified in the compilation settings of Project.   The compiler believes that all code before the directive # include "StdAfx.h" is precompiled and skips the # include "StdAfx. H "instruction, use PROJECTNAME.PCH to compile all code after this instruction. Therefore, the first statement of any CPP implementation file that requires a precompiled header file must be: #include "stdafx.h". You do not need to add the statement if the project does not require a precompiled header file.

Problem Solving Ideas:

Solution 1 is how this is done; Solution 2 is to turn off the precompiled header File option for the project, so you can, solution 3 and Solution 2 are similar, but more thoroughly, create a project that does not require precompiled header files directly by creating an empty project.

code example for solution 2:

Test.cpp's Code:

1 //Instructfile.cpp:Defines the entry point for the console application.2 //3#include"stdafx.h"4#include"myfile.h"5#include <iostream>6 7 intMainintargcChar*argv[])8 {9 MYFILE Pefile1;Ten Pefile1. GetType (); OneSystem"Pause"); A     return 0; -}

MyFile.cpp's Code:

1#include"stdafx.h"2 //the above line of code is critical and must be preceded by all valid code. 3#include"myfile.h"4#include <iostream>5 6 Myfile::gettype ()7 {8Std::cout <<"The file is a MZ header file."<<Std::endl;9}

MyFile.h's Code:

1 class MYFILE 2 {3public:4    GetType (); 5 };

Engineering FileView such as:

Just post the code for Scenario 1, and if you are interested you can try Scenario 2 and Scenario 3.

Three ways to troubleshoot "Fatal error C1010" error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.