C++ nested static structs/classes?

Started by
13 comments, last by Melekor 19 years, 3 months ago
Quote:Original post by izzo
Only constant static *integral* types can be initialised in the class declaration.


Quote:Original post by Melekor
struct Test{	static const int m_static = printf("hi");};


It is a constant static integral and yet it's not working. That's why I'm inclined to think this is a compiler problem, can someone confirm that?
Advertisement
Sorry, you posted while I was posting, so otherwise I would have commented above.

I had a look at the assembly output of your test case and it doesn't seem to call printf at all (I tried it in gcc and gcc doesn't even compile). So it looks like it's just ignoring the call to printf.. the value would be 0 because it is instantiated in an initialised data section (bss), I expect..

sam.


[Edited by - izzo on February 7, 2005 10:12:40 PM]
It is a compiler problem, as that code shouldn't compile!
main.cpp:8: error: `int printf(const char*, ...)' cannot appear in a constant-expressionmain.cpp:8: error: a function call cannot appear in a constant-expression

(edit) beaten to the punch!
Yeah, I'm using VC++ .NET 2003 Standard edition so I guess it's borked :( It seems to just ignore the call which is pretty strange..

sam.

[Edited by - izzo on February 7, 2005 10:14:19 PM]
Ok, thanks for clearing that up izzo and lucky_monkey.

This topic is closed to new replies.

Advertisement