[c++] Stupid inheritance error

Started by
2 comments, last by Mikle3 17 years, 1 month ago
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);
...

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

This topic is closed to new replies.

Advertisement