Static variable not initialized

Posted by Simon Linder on Stack Overflow See other posts from Stack Overflow or by Simon Linder
Published on 2010-04-27T10:51:39Z Indexed on 2010/04/27 10:53 UTC
Read the original article Hit count: 389

Hi all,

I've got a strange problem with a static variable that is obviously not initialized as it should be.
I have a huge project that runs with Windows and Linux. As the Linux developer doesn't have this problem I would suggest that this is some kind of wired Visual Studio stuff.

Header file

class MyClass
{
    // some other stuff here
    ...
    private:
        static AnotherClass* const Default_;
};


CPP file

AnotherClass* const Default_(new AnotherClass(""));
MyClass(AnotherClass* const var)
{
    assert(Default_);
    ...
}

Problem is that Default_is always NULL. I also tried a breakpoint at the initialization of that variable but I cannot catch it.

There is a similar problem in another class.
CPP file

std::string const MyClass::MyString_ ("someText");
MyClass::MyClass()
{
    assert(MyString_ != "");
    ...
}

In this case MyString_is always empty. So again not initialized.
Does anyone have an idea about that? Is this a Visual Studio settings problem?
Cheers Simon

© Stack Overflow or respective owner

Related posts about visual-studio-2008

Related posts about c++