base class initializations plez help
class Cobject
{
public:
float xpos; //positions and rotation
float ypos;
float zpos;
float yrot; //rotation of the z axis
};
class Ccamera: public Cobject
{
public:
Ccamera(): //constructor
movespeed(.01f),
turnspeed(3.14f*2.0),
yrot(D3DX_PI/4)
{};
float sight; //how far to draw
float movespeed; //in units/secs
float turnspeed;
};
those are my two classes. i get this error.
''Ccamera'' : illegal member initialization: ''yrot'' is not a base or member
if i remove the yrot(D3DX_PI/4), the code compiles so i know i can''t be completely wrong. can someone tell me the proper way to initialize yrot without writing another funciton?
It looks as though your code is pretty messed up due to the post. Retry it using the "
" tags so that we can actually see the code in it''s correct form.
" "
Try putting yrot = D3DX_PI/4 in the body of the constructor, in stead of in the initialization list. Or provide a constructor in the base class which can set yrot, so you can call that in the initialization list. You probably can''t set base class variables in the initialization list.
You can''t set individual base class variables. You have treat the base class as if it was a single variable in the current class, which essentially means that you call one of its constructors. So you''d need a constructor in Cobject that took a float and set yrot to equal that.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
Your constructor ends with a semicolon. Should be like this:
class Ccamera: public Cobject{public:Ccamera(): //constructormovespeed(.01f),turnspeed(3.14f*2.0),yrot(D3DX_PI/4){} <--- your semicolon here might give u headache.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement