TITLE: nested structures initialization (Source: comp.lang.c++.moderated, 23 Dec 2000) BELOFAST: Nickolay.Belofastow@ieee.org >> // This is in the global scope! >> struct cTest1 >> { >> int a; >> int b; >> }; >> >> const cTest1 v1 = {1, 2}; >> >> struct cTest2 >> { >> int c; >> cTest1 d; >> }; >> >> const cTest2 v2 = {3, v1}; // Error here >> >> In the last line, where I try to initialize v2 variable, my compiler >> gives me an error message. I tested with both MS Visual C++ 6.0 and >> Borland C++ 5.02 -- the same results. Both compilers could not >> initialize filed d of cTest2, complaining "there is no conversion from >> cTest1 to int". ROOZEMAAL: Peter Roozemaal >I can't find a problem with this code; neither does gcc. Could it be >compiler bugs? CLAMAGE: "Stephen Clamage" Originally, you could not use a structured value to initialize a class member using brace-initialization. You would have to write CTest2 v2 = { 3, {1, 2} }; // the inner braces are not required A relatively recent addition to the C++ standard allows the code you show above. Not all compiles implement the feature yet. _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com