Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

anotherfantasy

base class initializations plez help

This topic is 5894 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

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?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
Your constructor ends with a semicolon. Should be like this:

class Ccamera: public Cobject
{
public:
Ccamera(): //constructor
movespeed(.01f),
turnspeed(3.14f*2.0),
yrot(D3DX_PI/4)
{} <--- your semicolon here might give u headache.

Share this post


Link to post
Share on other sites

  • 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!