我构建子类对象的方式有什么问题?

时间:2016-12-04 10:49:07

标签: c++ class inheritance mfc

这是我的子类:

class BackGround :public Object{
public:
BackGround(int y){
    character.Load(_T("wallpaper.png"));
    x = 0;
    this->y = y;
    direct = 0;
    width = 1200;
    height = 375;
}
};

我的基类:

class Object{
public:
CImage character;     
int x;             
int y;
int direct;       
int speed;
int width;      
int height;
int Xcenter;
int Ycenter;

Object(){}

void draw(HDC hDC){
    character.Draw(hDC, x, y, width, height, 0, direct*height,width, height);
}
};

当我创建BackGround类的对象时,        BackGround Bg1(0); BackGround Bg2(-WINDOW_HEIGHT);

出现错误:

1>  MainFrm.cpp
1>c:\users\desktop\mfcgame\mfcgame\childview.h(46): error C2059: syntax error: 'const'
1>c:\users\desktop\mfcgame\mfcgame\childview.h(47): error C2059: syntax error:“-”
1>  MFCGame.cpp
1>c:\users\desktop\mfcgame\mfcgame\childview.h(46): error C2059: syntax error: 'const'
1>c:\users\desktop\mfcgame\mfcgame\childview.h(47): error C2059: syntax error:“-”
1>  ChildView.cpp
1>c:\users\desktop\mfcgame\mfcgame\childview.h(46): error C2059: syntax error: 'const'
1>c:\users\desktop\mfcgame\mfcgame\childview.h(47): error C2059: syntax error:“-”
1>c:\users\desktop\mfcgame\mfcgame\childview.cpp(67): error C2228: left of '.draw' must have class/struct/union type
1>c:\users\desktop\mfcgame\mfcgame\childview.cpp(68): error C2228: left of '.draw' must have class/struct/union type
1>c:\users\desktop\mfcgame\mfcgame\childview.cpp(116): error C2228: left of '.y' must have class/struct/union type
1>c:\users\desktop\mfcgame\mfcgame\childview.cpp(118): error C2228: left of '.y' must have class/struct/union type
1>c:\users\desktop\mfcgame\mfcgame\childview.cpp(120): error C2228: left of '.y' must have class/struct/union type
1>c:\users\desktop\mfcgame\mfcgame\childview.cpp(122): error C2228: left of '.y' must have class/struct/union type

0 个答案:

没有答案