开发者

constructor of global static member not being called when compiled with rvct

Well, this is kind of complex to explain. I'm compiling a static library which has a header that looks something similar to this:

class Foo{
    static int Goo(){
        DoSomethingExciting();
        return 0;       
    }
    static int fooMember;
}

In the Cpp i have an initialization of the fooMember:

int Foo::fooMember = Foo::Goo();

When linking the static library to an application i'm writing, the Goo method which is supposed to be called isn't being called. To be exact, the DoSomethingExciting() method isn't called at all. I do use the Foo class in the application. When i put the line:

int Foo::fooMember = Foo::Goo();

in a cpp in my application (of course i remove the same line from the static library), I see that the Goo() is called.

I'm not sure how to name the problem i'm experiencing, I guess it is a problem with global static member initialization or something like that.

I'm using RVCT to compile. When compiling开发者_StackOverflow中文版 the same scenario in Visual Studio, everything works great. I'm guessing that RVCT behaves differently and I might need to add some compilation flags.

Btw, I've also tried using a decompiler on my compiled executable and I didn't see any calls to Goo(), although i did see that the method is in the file.

I hope i was clear enough with my problem :)

Thanks in advance...


It would be called if it was a constructor of a static object, but since it is only a static method, why would a call to it be generated automatically?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜