Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Problems with constructor of static member class

2005-06-28 by soren_t_hansen

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

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.