Sign in to follow this  

[c++] Stupid inheritance error

This topic is 3930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Argh, I hate cpp... I'm sure I'm doing something very stupid here, and that's probably why the compiler is shouting at me. So where's me mistake? Must I spell the constructor out for the compiler? You probably want the error: error C2661: 'Paddle::Paddle' : no overloaded function takes 3 parameters And the code: Sprite.h...The constructor is implemented...
class Sprite
{
public:
...
	//Initialize the sprite in a specified location (x,y).
	Sprite(char *sFileName, int nStartX, int nStartY);
...
};

Paddle.h, as you see no redefinition of a constructor...
class Paddle:public Sprite
{
public:
	SDL_Rect Move(int nDeelta);

protected:
private:
};

Main.cpp
...
Paddle paddleMain = Paddle(PADDLE_IMAGE, 100, 500);
...

Share this post


Link to post
Share on other sites
Unfortunately, constructors cannot be inherited, so you'll have to explicitly write them for each derived class:

Paddle(char *sFileName, int nStartX, int nStartY) :
Sprite(sFileName, nStartX, nStarty)
{
}


I'd probably prefer aggregation (having a Sprite as a member of Paddle) over inheritance — is a Paddle really a Sprite, or does it have a Sprite instead?

Share this post


Link to post
Share on other sites
Constructors are not inherited, you will need to define a constructor in your Paddle class:

Paddle( char * filename, int x, int y ) : Sprite( filename, x, y ) {}




Oh and I recommend you look into std::string instead of using null-terminated character arrays.


jfl.

[Edit: Too slow.]

Share this post


Link to post
Share on other sites

This topic is 3930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this