Jump to content
  • Advertisement
Sign in to follow this  
Mikle3

[c++] Stupid inheritance error

This topic is 4217 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
Advertisement
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
I knew it was something stupid like that...Thank very much dude...This code has been haunting me for a few hours :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!