You can''t initialize those members in a class definition, you must do it in the constructor. Try this, it should work:
class CPong
{
public:
CPong();
~CPong();
private:
CPaddle Player1;
CPaddle Player2;
};
CPong::CPong() :
Player1("images\\bluechucks.bmp"),
Player2("images\\yellowchucks.bmp")
{}
Class constructor problem
quote: Original post by nino
how can i make it so that i can call the CPaddle constructor automatically when the CPong class is created but still have the CPaddle instance usable throughout the whole life of the CPong class?
define the Player1 and Player2 as pointers. Then create them by using new within the constructor of the CPong class (and delete in the destructor) and this particular problem is solved.
cmaker- I do not make clones.
Just use pointers and create the paddles in the CPong constructor :
This way the paddles are built when the CPong is built.
--------
Andrew
class CPong{ public: CPong() { Player1 = new Paddle("images/bluechucks.bmp"); Player2 = new Paddle("images/yellowchucks.bmp"); } ~CPong() { delete Player1; delete Player2; } private: CPaddle *Player1; CPaddle *Player2;};
This way the paddles are built when the CPong is built.
--------
Andrew
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement