Error c2143: syntax error: Missing '; 'before '*'

Source: Internet
Author: User

During the VC programming process, we often encounter the following error message: Error c2143: syntax error: Missing '; 'before' *', that is, "*" is missing before "*". ". Why?

Background: A compilation error occurs when the mainframe class contains the cview. h file.

Next, let's first look at the error message of the compiler:

-------------------- Configuration: splitter-Win32 debug --------------------
Compiling...
Mainfrm. cpp
F: \ c ++ pratice \ Vc \ test \ splitter \ splitterview. H (21): Error c2143: syntax error: Missing '; 'before '*'
F: \ c ++ pratice \ Vc \ test \ splitter \ splitterview. H (21): Error c2501: 'csplitterdoc ': Missing storage-class or type specifiers
F: \ c ++ pratice \ Vc \ test \ splitter \ splitterview. H (21): Error c2501: 'getdocument': Missing storage-class or type specifiers
Error executing cl.exe.

Splitter.exe-3 error (s), 0 warning (s)

We can double-click the left mouse button on the first error prompt. VC ++ will open the cview header file in the code editing window and locate the position shown by the cursor.

 

This error is often encountered in program development. In fact, it is not the case that a semicolon should be added before the * sign as the error message says, but the program does not know the csplitterdoc class. We know that only the source files are involved in the compilation of the C ++ program. We added the splitterview to the front of the source files of the cmainframe class. code # include "splitterview. H ". Therefore, when compiling the source file of the cmainframe class, the splitterview is displayed when this line of statements is encountered. but the file references the undefined splitterdoc. class H, so the compiler will report the above error information. Why is there no error during compilation when the source file of the class contains its header file? Let's take a look at the source file of the splitterview class. Below are the statements she started:

// splitterView.cpp : implementation of the CSplitterView class//#include "stdafx.h"#include "splitter.h"#include "splitterDoc.h"#include "splitterView.h"

As you can see, the splitterview. cpp file contains the content of the splitterdoc. H class file before it contains the splitterview. h file, which is defined by the splitterdoc class. Then expand the splitterview. h file. This is the definition of the splitterdoc class that the compiler knows. In fact, to solve the above errors, the compiler should understand the splitterdoc class definition before referencing the splitterview class definition. Therefore, to solve the problem, you can move the definition statements containing the document class in the View class source file to the header file of the View class and place them before the definition of the View class. Cut "# include" in splitterview. cpp.
"Splitterdoc. H", this line of statements, and paste it to the front of the splitterview. h file. The following is the front code of the modified splitterview. h file.

// splitterView.h : interface of the CSplitterView class///////////////////////////////////////////////////////////////////////////////#if !defined(AFX_SPLITTERVIEW_H__540E2E9D_94E3_4728_8C56_A95C12F3ACE2__INCLUDED_)#define AFX_SPLITTERVIEW_H__540E2E9D_94E3_4728_8C56_A95C12F3ACE2__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#include "splitterDoc.h"class CSplitterView : public CView{protected: // create from serialization onlyCSplitterView();DECLARE_DYNCREATE(CSplitterView)

Compile again, OK! At this time, the program passed smoothly and the problem was solved.

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.