Skip to main content
gamedev.net
🔒 Locked

Initializer List Problems

Started by Drew_Benton Jan 3, 2005 at 6:35 PM 3 replies 450+ views
Original Post
Drew_Benton
Drew_Benton
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]
CJH
CJH
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;}
antareus
antareus
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.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Drew_Benton
Drew_Benton
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.