![]() |
![]() |
![]() |
static class members boring question...
Alex.ro
I just tested this:
Chris Ormerod
And I tested utilising that static variable like this:
Chris Ormerod
Judging by the trailing semi-colon for the first post, and lack of such in the second post, the first post is talking about C++, and the second about C#.
Sum Dum Gai
iirc, only int static members can be initialised in the declaration, rather than needing a definition. I think codewarrior allows floats to be initialised in place as well. At any rate, things are limited to primatives.
i like i
Well there you go, I don't do C++ - sorry.
Chris Ormerod
What did you think the text "x::val" would represent in C#?
grouch
Actually, the C++ standard allows const static members to be initialized in the class declaration, but non-const static members are just like global variables, and they have to follow the "one-definition rule". Having the definition in the class means that there are more than one file in which that variable is defined, which causes problems for the linker, as it would have to pick which definition you really want.
Ben Combee
Tried putting a global in a header file recently?
Mr Jack
>> Tried putting a global in a header file recently?
Alex.ro
1%, if you're lucky. :-p
Brad Wilson (dotnetguy.techieswithcats.com)
Static variables must be placed in a specific compilation unit - an actual source file. Declaring a "const int" variable is more like having a #define (well, sort of).
igor
"Static data members are not part of objects of a given class type; they are separate objects. As a result, the declaration of a static data member is not considered a definition. The data member is declared in class scope, but definition is performed at file scope. "
maaakri
|