Class constructor problem
i''m making a pong game for my first game and i have 3 classes: CBall, Cpong and Cpaddle and i want to include 2 instances of CPaddle as private data members of CPong here is the code for the CPong.h file
class CPong
{
public:
CPong();
~CPong();
private:
//my problem is here:
CPaddle Player1("images/bluechucks.bmp");
CPaddle Player2("images/yellowchucks.bmp");
};
my problem is with creating the CPaddle objects I get this error:
error C2059: syntax error : ''string''
i think this error means that you can''t send stuff to the
CPaddle constructor if it''s in a class definition.
how can i make it so that i can send something to the CPaddle class constructor?
thanks in advance
NiNo
You need to put the accepted parameters in an overloaded constructor
i.e.
CPaddle(const char *szName)
i.e.
CPaddle(const char *szName)
sorry i forgot to say that i did that here''s my overloaded constructor
CPaddle(LPCTSTR);
so i know it sends it there but it won''t let me do it in the class definition
thanks
NiNo
CPaddle(LPCTSTR);
so i know it sends it there but it won''t let me do it in the class definition
thanks
NiNo
quote:
You need to put the accepted parameters in an overloaded constructor
i.e.
CPaddle(const char *szName)
wrong . Its the way you defined your file path, nino. I had this same problem a while ago - in C++, the "\" character is used for stuff like tabbing (\t), line carriage (\n), etc. What causes the error is C++ interprets "images/bluechucks.bmp" as "images \b luechucks.bmp". Since there is no such thing as "\b", you get the error. How do you fic it? Simple - use "\\". Peace.
==============================
"Need more eeenput..."
- #5, "Short Circuit"
==============================
Edited by - Gaiiden on November 15, 2000 3:32:23 PM
Edited by - Gaiiden on November 15, 2000 3:43:16 PM
Drew Sikora
Executive Producer
GameDev.net
Gaiiden that''s not the problem i used the same string in a different function and it works fine also i used
these / not \
Twoflower even if i use a variable it gives the same error
can anyone help me!!!!??!?!?
NiNO
these / not \
Twoflower even if i use a variable it gives the same error
can anyone help me!!!!??!?!?
NiNO
I''ve just re-read your orignal question and it seems I missed the obvious.
You CAN''T call an overloaded constructor from the class definition since this is just a definition, not actual code.
You CAN''T call an overloaded constructor from the class definition since this is just a definition, not actual code.
quote: Original post by nino
Gaiiden that''s not the problem i used the same string in a different function and it works fine also i used
these / not \
NiNO
Yeah, you did didn''t you? Huh. Never tried that. Guess it would work tho. Ah well, tried.
==============================
"Need more eeenput..."
- #5, "Short Circuit"
==============================
Drew Sikora
Executive Producer
GameDev.net
thanks for trying at least Gaiiden
TwoFlower: if i can''t call an overloaded constructor from a class definition then how can i call it?
i''ve tried doing it in a function and it works fine but then as soon as that function ends the instance gets destroyed
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?
thanks alot guys
NiNo
TwoFlower: if i can''t call an overloaded constructor from a class definition then how can i call it?
i''ve tried doing it in a function and it works fine but then as soon as that function ends the instance gets destroyed
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?
thanks alot guys
NiNo
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement