C ++ - "Member function not declared" in derived class

I have a problem in MSVC ++ 2008, where VS2008 throws this compilation error:

error C2509: 'render' : member function not declared in 'PlayerSpriteKasua' 

Now, what confuses me is that render () is defined, but in an inherited class.

The class definition works as follows:

 SpriteBase -Inherited By-> PlayerSpriteBase -Inherited By-> PlayerSpriteKasua 

So, the corrected version of SpriteBase.h is this:

 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; }; 

And finally, PlayerSpriteKasua.h:

 class PlayerSpriteKasua : public PlayerSpriteBase { public: }; 

I know that it has no members, but that is simply because I could not add them. The same goes for PlayerSpriteBase; there was another matter.

Code in 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; } 

When I type, say void PlayerSpriteKasua:: , Intellisense pops up, listing all the members of PlayerSpriteBase and SpriteBase just fine, but it fails when compiling, as I said above.

Is there any special reason why I get this error?

PlayerSpriteBase.cpp is empty and has nothing yet.

SpriteBase.cpp has many function definitions for SpriteBase and uses the same format as PlayerSpriteKasua.cpp:

 void SpriteBase::died() { return; } 

- an example.

+6
c ++ inheritance class virtual abstract
source share
3 answers

In PlayerSpriteKasua.h, you need to re-declare all methods that you are going to override / implement (without "= 0" to say that these methods are no longer abstract). Therefore, you need to write it as follows:

 class PlayerSpriteKasua : public PlayerSpriteBase { public: virtual void think(); virtual void render(long long ScreenX, long long ScreenY); virtual int getHealth(); }; 

... or did you omit this to keep your post shorter?

+16
source share

You need to provide an declaration for PlayerSpriteKasua :: render () in your class definition. Otherwise, other translation units, including your PlayerSpriteKasua.h, will not be able to say that you provided the definition, and would have to conclude that PlayerSpriteKasua could not be created.

+2
source share

You need to update the SpriteBase elements that you intend to implement in PlayerSpriteKasua in the PlayerSpriteKasua declaration in PlayerSpriteKasua.h.

+2
source share

All Articles