Jump to content
  • Advertisement
Sign in to follow this  
Drew_Benton

Initializer List Problems

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

I am having troubles with a specific initializer list, I'm sure I am not doing something right - but I cannot figure out what:
class CInput
{
...
public:
   int INPUT_ESCAPE;
...
};
class CInputW32 : public CInput
{
private:
...
public:
...
};
CInputW32::CInputW32() : 
//INPUT_ESCAPE(VK_ESCAPE)  // does not work, neither dies CInput::INPUT_ESCAPE(VK_ESCAPE)
{
	INPUT_ESCAPE = VK_ESCAPE; // works but I want to use initilizer list to make it look neater.
}
If I use the first initializer list code - I get:
   error C2614: 'CInputW32' : illegal member initialization: 'INPUT_ESCAPE' is not a base or member
If I use the second code - I get:
   error C2039: 'INPUT_ESCAPE' : is not a member of 'CInput'
Can someone please point out what I am doing wrong - or is this concept not right? Thanks for your time and patience. - Drew [Edited by - Drew_Benton on May 25, 2005 9:48:09 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hmm, perhaps you can't initialise a base member in an initializer list. In that case,

class in
{
public:
int a;
in(int a_) : a(a_ = int())
{
}
};

class win : public in
{
public:
win(int a_) : in(a_)
{
}
};

int main()
{
win r(5);
return 0;
}



Share this post


Link to post
Share on other sites
You can't initialize base members in derived initializer lists. You have to delegate initialization to the base's constructor. You can initialize them in the body of the constructor, however.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can not use intializer list in derive class on base varaiables.
So, your code which does not work:

CInputW32::CInputW32() :
INPUT_ESCAPE(VK_ESCAPE)
{
}



Should be:

CInput::CInput() :
INPUT_ESCAPE(VK_ESCAPE)
{
}



Variables have to be initialized in the class they are declared, and in your case you declared INPUT_ESCAPE in CInput class, not in CInputW32.

Also, may I suggest to use mix case for you member variable names, since all upper case usually means #define

Share this post


Link to post
Share on other sites
Aww darn! :( Thank you everyone! I was really wondering why it wasn't working - and using the CInput initializer list does me no good, so I guess I will have to stay with what works. Thanks again!

- Drew

[Edited by - Drew_Benton on May 25, 2005 9:12:17 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

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