PDA

View Full Version : C++0x error - "error: braces around initializer for non-aggregate type"



trilobite
August 3rd, 2009, 05:56 AM
Hi all -

I'm trying to compile a program using g++ version 4.3.3, and using the "-std=c++0x" compiler option.

I'm trying to initialise a vector as follows-
vector <string> myvec = {"foo", "bar", "baz"};

Now, I've had a look around the web to check the new C++0x initialisation syntax, and (to me) this looks exactly like this example that I saw -
vector<string> vs={ "ab", "cd", "ef"};

Yet, when I try to compile the code, I get this error -
"error: braces around initializer for non-aggregate type"

Very odd. I've used the syntax that I've seen, yet the compiler is complaining. So, does anyone know the reason (and the fix) for this?

Very many thanks in advance for your help!
- trilobite

Sockerdrickan
August 3rd, 2009, 07:17 AM
use gcc-snapshot, 4.3.3 sucks
and you don't need the =

trilobite
August 3rd, 2009, 07:29 AM
use gcc-snapshot, 4.3.3 sucks
and you don't need the =

Ahh... thanks very much, Tux0r! Yes, that's got rid of the error (and I agree - 4.3.3 does seem to be a bad release). I'll try the snapshot releases and see how they go.
Thanks again - bye for now -
- trilobite