简体   繁体   English

错误C2146:语法错误:缺少';' 在标识符'm_ball'C ++之前

[英]error C2146: syntax error : missing ';' before identifier 'm_ball' C++, MFC

I have beloved error C2146. 我钟爱的错误C2146。 I checked for possible errors and I'm unable to find one( as far as I can see there are all needed ; and after rightclick on Ball->GoToDefinition it correctly shows class declaration) 我检查了可能的错误,但找不到一个(据我所知,所有这些都需要;在Ball-> GoToDefinition上单击鼠标右键后,它会正确显示类声明)

BallMasterDoc.h BallMasterDoc.h

#pragma once
class CBallMasterDoc : public CDocument
{
private:
    Ball m_ball; //syntax error : missing ';' before identifier 'm_ball'
    Pod m_pod; //syntax error : missing ';' before identifier 'm_pod'

BallMasterDoc.cpp BallMasterDoc.cpp

#include "Pod.h"
#include "Ball.h"
#include "BallMasterDoc.h"

Ball.h

#pragma once

const COLORREF BLUE = RGB(0, 0, 255);
extern int g_iRadius, g_iHeight;
extern int g_iWidth, g_iMaxWidth;//pod...

class Ball
{
public:
    Ball();
    ~Ball();
    BOOL Move(CPoint podPosition);
    BOOL Start(){ return m_bStart; }
    BOOL Collision(){ return m_bCollision; }
    BOOL End(){ return m_bEnd; }
    CRect GetArea();
private:
    BOOL CheckCollision(CPoint podPosition);
    float m_fDirection;
    int m_iB; // y = ax + B
    BOOL m_bUpDown;//true - up
    BOOL m_bStart;
    BOOL m_bCollision;
    BOOL m_bEnd;
    CPoint m_ballCentre;
    CPoint m_collisionPoint;
};

Pod.h 播客

#pragma once
const COLORREF BLACK = RGB(0, 0, 0);
extern int g_iWidth, g_iMaxWidth;
class Pod
{
public:
    Pod();
    ~Pod();
    BOOL MoveLeft();
    BOOL MoveRight();
    CPoint Position() { return m_Middle; }
private:
    CPoint m_Middle;
};

Please tell me what's wrong. 请告诉我怎么了。

EDIT 编辑

All includes are in cpp files(those generated by wizard and mine) I show just these 3 cause rest is imo uninvolved in this case. 所有包含的内容都在cpp文件中(这些文件由向导和我的向导生成),我只显示这3个原因,在这种情况下,imo不起作用。 I'm learning MFC from magic book called: Microsoft Visual C++ Windows Applications by Example and there all includes go to cpp files(even if I feel its strange and book is far from best wizard supports this style...) 我正在从名为《 Microsoft Visual C ++ Windows Applications by Example》的魔术书中学习MFC,并且所有内容都包括转到cpp文件的内容(即使我觉得它很奇怪,并且本书远非最好的向导也支持这种样式...)

好的,我将#include"Ball.h"/"Pod.h"放在BallMasterDoc.h中 ,它解决了这个问题,但这不能满足答案,只要魔术书曾经提供过有效的代码即可(当然,这不是确切的程序,对我来说,大部分该代码仍然无法正常工作),但现在已经没有关系了

Since BallMasterDoc.h depends on knowing about the Ball and Pod classes, that header file should include Ball.h and Pod.h -- instead of relying on whichever .cpp included BallMasterDoc.h to also include those other headers. 由于BallMasterDoc.h依赖于对BallPod类的了解,因此该头文件应包含Ball.hPod.h ,而不是依赖于BallMasterDoc.h包括的任何.cpp也包括那些其他头文件。

The BallMasterDoc.cpp that you posted looks OK, so your errors likely come from another .cpp file which does include BallMasterDoc.h but did not include the headers required by that header. 您发布的BallMasterDoc.cpp看起来BallMasterDoc.cpp ,因此您的错误可能来自另一个.cpp文件,该文件确实包含BallMasterDoc.h但没有包含该标头所需的标头。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误C2146:语法错误:缺少';' 在标识符之前 - error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在标识符'A1'之前缺少',' - Error C2146: syntax error : missing ',' before identifier 'A1' 错误C2146:语法错误:缺少';' 在标识符之前 - Error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:缺少';' 在标识符'ContextRecord'之前 - error C2146: syntax error : missing ';' before identifier 'ContextRecord' C ++错误1错误C2146:语法错误:缺少';' 在标识符“记录”之前 - C++ Error 1 error C2146: syntax error: missing ';' before identifier 'records' 错误:C2146:语法错误:缺少';' 在标识符“ m_Employer”之前, - error: C2146: syntax error : missing ';' before identifier 'm_Employer', 模板Fn指针错误C2146:语法错误:缺少';' 在标识符之前 - Template Fn Pointer error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在按功能传递地图时,在标识符mType之前缺少',' - error C2146: syntax error : missing ',' before identifier mType when passing a map by function VC ++错误C2146:语法错误:标识符'pFirst'之前缺少')' - VC++ error C2146: syntax error : missing ')' before identifier 'pFirst' 错误C2146:语法错误:缺少';' 在标识符“ g_App”之前 - error C2146: syntax error : missing ';' before identifier 'g_App'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM