Sam wrote:
> Hi,
> I need to initialize a static data member by calling a method of
> another static member. Like:
>
> class A
> {
> public:
> static int TYPE;
> private
> static Type _s_type;
> };
>
> int A::TYPE = _s_type.ID();
> Type A::_s_type;
>
> I compiled the code with my compiler. But I'm not sure whether it
> complies with the standard.
I complies in a sense that it's well-formed. However, it has undefined
behaviour because when you try to initialise A::TYPE, A::_s_type, which
you need, hasn't been initialised properly yet. Reorder their definitions.
V
|