[try Beta version]
Not logged in

 
 
Member intializer list error...

Oct 24, 2015 at 4:32pm
1
2
3
4
5
6
7
8
9
10
11
class Something
{
public:
	Something(string n)
		:a{ n }, b{ 10 }, c{ 10 } {};

private:
	string a;
	int b;
	int c;
};


gives the error: error C2797: 'Something::a': list initialization inside member initializer list or non-static data member initializer is not implemented

However,

1
2
3
4
5
6
7
8
9
10
11
class Something
{
public:
	Something(string n)
		:b{ 10 }, c{ 10 } { a = n; };

private:
	string a;
	int b;
	int c;
};


Compiles without any error. Can someone please tell me why?
Last edited on Oct 24, 2015 at 4:34pm
Oct 24, 2015 at 4:36pm
Your compiler is too old. The error message say this way of initializing data members has not been implemented yet. The code compiles fine for me with GCC 4.9.2.
Last edited on Oct 24, 2015 at 4:41pm
Oct 24, 2015 at 4:42pm
Too old to compile

1
2
Something(string n)
		:a{ n } {};


but not too old to compile

1
2
	Something()
		:b{ 10 };


?

I'm using VS Community 2013, and I'm fairly certain I've intitialized strings in a class using a member initializer list. I don't see how my compiler can be too old quite frankly.
Oct 24, 2015 at 4:44pm
Last edited on Oct 24, 2015 at 5:00pm
Oct 24, 2015 at 5:13pm
Awesome! Tyvm! I just discovered VS 2015 existed, I'm updating now. Thanks for your help!
Topic archived. No new replies allowed.