Re: c++ static object not created

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kövesdi György wrote:
>> static SomeClass my_instance;
>>
>> I found that if there is no reference to this instance, then gcc does not
>> call its constructor at all.
>> How can it be forced?
> 
> I found that if there is another similar object in this file which is 
> referenced externally, then the constructor of my_instance is also called, 
> even if it is marked static, and has no references.

Can you give us an example of this not working?  It really should work,
and it works for me.  The example must be complete: it must be possible
to compile and run the program.

#include <iostream>

using namespace std;

class SomeClass
{
public:
  SomeClass()
  {
    cout << "Hello!\n";
  }
};

static SomeClass my_instance;

int main()
{
}

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux