C + + header file The class declaration after forgetting to add a semicolon produces an unexpected compilation error

Source: Internet
Author: User
Tags header

The contents of the header file Test.h are

class Test
{
public:
virtual void test1(); 
}

The implementation file is

Test.cpp
#include "Test.h"
#include <iostream>
using namespace std;
void Test::test1(){ cout<<"Hello"<<endl; }

An error occurred at compile time

c:\program files\microsoft visual studio\vc98 \include\errno.h(29) : error C2143: syntax error : missing ';' before 'string'
c:\program files\microsoft visual studio\vc98\include\errno.h(29) : fatal error C1004: unexpected end of file found

Do not connect these two files to consider it is difficult to know is there is wrong, and Unmi originally write Java is much more than C + +, Java can not #include usage, in fact, have C + + experience, understand the #include只是把被包含文件的内容引入到当前位置.

The above inserts the contents of the Test.h into the Test.cpp file #include "Test.h", it should be noted that the class declaration must be followed by a semicolon, you can take the class declaration as a normal variable declaration statement, need to end a semicolon, or there will be many unpredictable compilation errors

The type of error is not just the above, the main content of the document introduced to the current position, and then the statement difference between a semicolon will be a syntax error, so you should form a class declaration after the good habit will not be wrong.

such as the implementation of the file written

#include "Test.h"
void Test::test1(){}

The mistake that comes up is

#include "Test.h"
void Test::test1 () {}
C:\Documents and Settings\yanbin\my documents\visual Studio 

Projects\testvirtual\test.cpp (3): Error C2628: ' Test ' followed by 

' void ' are illegal (did you forget a '; ')
C:\Documents and Settings\yanbin\my documents\visual Studio 

projects\testvirtual\test.cpp (3): Error C2556: ' Class Test __thiscall 

test::test1 (void) ': overloaded function differs only with return type from 

' void __thiscall test::t Est1 (void) '
C:\Documents and Settings\yanbin\my Documents\Visual Studio 

projects\testvirtual\test.h (4): Declaration of ' test1 '
C:\Documents and Settings\yanbin\my documents\visual Studio 

projects\testvirtual \test.cpp (3): Error C2371: ' test1 ': 

redefinition different basic types
c:\documents and Settings\yanbin\my D Ocuments\visual Studio 

projects\testvirtual\test.h (4): declaration ' test1 '

Because the compiler sees no semicolon between the class declaration of the header file and the statement void Test::test1 () {}.

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.