我在 MSVC++ 2008 中遇到问题,VS2008 抛出此编译错误:
error C2509: 'render' : member function not declared in 'PlayerSpriteKasua'
现在,让我感到困惑的是 render() 是定义的,但是在一个继承的类中。
类定义的工作方式如下:
SpriteBase -Inherited By-> PlayerSpriteBase -Inherited By-> PlayerSpriteKasua
因此,SpriteBase.h 的精简版本如下:
class SpriteBase {
public:
//Variables=============================================
-snip-
//Primary Functions=====================================
virtual void think()=0; //Called every frame to allow the sprite to process events and react to the player.
virtual void render(long long ScreenX, long long ScreenY)=0; //Called every frame to render the sprite.
//Various overridable and not service/event functions===
virtual void died(); //Called when the sprite is killed either externally or via SpriteBase::kill().
-snip-
//======================================================
};
PlayerSpriteBase.h 是这样的:
class PlayerSpriteBase : public SpriteBase
{
public:
virtual void pose() = 0;
virtual void knockback(bool Direction) = 0;
virtual int getHealth() = 0;
};
最后,PlayerSpriteKasua.h 是这样的:
class PlayerSpriteKasua : public PlayerSpriteBase
{
public:
};
我知道其中还没有成员,但这仅仅是因为我还没有添加它们。PlayerSpriteBase 也是如此;还有其他的东西要进去。
PlayerSpriteKasua.cpp 中的代码是这样的:
#include "../../../MegaJul.h" //Include all the files needed in one go
void PlayerSpriteKasua::render(long long ScreenX, long long ScreenY) {
return;
}
void PlayerSpriteKasua::think() {
return;
}
int PlayerSpriteKasua::getHealth() {
return this->Health;
}
当我输入时void PlayerSpriteKasua::
,Intellisense 会弹出列出 PlayerSpriteBase 和 SpriteBase 的所有成员,但在编译时它会像我上面所说的那样失败。
我收到这个错误有什么特别的原因吗?
PlayerSpriteBase.cpp 是空的,目前还没有任何内容。
SpriteBase.cpp 有很多 SpriteBase 的函数定义,和 PlayerSpriteKasua.cpp 使用相同的格式:
void SpriteBase::died() {
return;
}
是一个例子。