struct test
{
int a;
int b;
char str[20];
};
int main()
{
test t;
cout <<t.a<<' '<<t.b<<' '<<t.str; // Will print garbage -1990867164 -2 b◄Ļu╝[’uÓ→@
cout <<endl;
test t2={}; // or {0}
cout <<t2.a<<' '<<t2.b<<' '<<t2.str; // Will print 0 0
cout <<endl;
// Initisalize each member of struct
test t3={1,2,"Hello"};
cout <<t3.a<<' '<<t3.b<<' '<<t3.str; // Will print 1 2 Hello
}
does it mean like:
//default constructor of test
test (): variable_of_test(0){}
I don't know but it can be used to initialize const members:
1 2 3 4 5 6 7 8 9 10
struct test
{
constint a;
};
int main()
{
test t; // error: structure with unitialized const members
test t={10}; // ok
}
I thought that a brace-enclosed initializer list could only be used to initialise a 'plain old data' (i.e. C) struct. So when I see code like
test test1 = {0}
I understand test to be a 'pod' struct, with no need for an actual constructor.
Andy
Of course, C++0x is changing this rule, but my gcc quoted C++98 at me when I tried to use a brace-enclosed initializer list with a class which had a constructor.. I was told to use normal constructor notation.