> This is done by redeclaring the _static_ varialbe using the scope
> resolution operator to identify the class to which it belongs.
> This causes storage for the varialbe to be allocated.
I belive I already do this? In the 2 lines just below (Source)?
> Try not to use statics within classes - generally
> also - if this program probably would work - it's not really good code.
I know that the style isn't great, but it is the best way to approach
the problem we have at hand :o)
/Søren
> > Hi all.
> >
> > I suspect the GNUARM compiler to have a flaw, since the following code
> > doesn't work as intended:
> >
> > (Header)
> > class A
> > {
> > public:
> > A(int x);
> > int m_x;
> > static A* get_a_Instance();
> >
> > private:
> > static A m_a;
> > static A m_b;
> >
> > };
> > (Source)
> > A A::m_a(1);
> > A A::m_b(2);
> >
> > A::A(int x)
> > {
> > m_x = x;
> > }
> >
> > A* A::get_a_Instance()
> > {
> > return &m_a;
> > }
> >
> > int main()
> > {
> > A* temp_a = get_a_Instance();
> > int x = temp_a->m_x;
> > }
> >
> > The problem is that the constuctor doesn_t get called, causing m_x to
> > have a garbage value (or 0). Even if I make an object of type A first,
> > it doesn't work.
> > Is it something I have to setup in my startup.s file?
> >
> > Best Regards
> > Søren
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]Message
Re: Problems with constructor of static member class
2005-06-28 by soren_t_hansen
Attachments
- No local attachments were found for this message.