Re: Verification of initialization of global objects???
Igor.Smirnov_at_cern.ch
Date: 03/12/04
- Next message: Hattuari: "Re: How did C++ beat the competition?"
- Previous message: Claudio Puviani: "Re: How did C++ beat the competition?"
- In reply to: Rolf Magnus: "Re: Verification of initialization of global objects???"
- Next in thread: Howard: "Re: Verification of initialization of global objects???"
- Reply: Howard: "Re: Verification of initialization of global objects???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 12 Mar 2004 16:19:46 +0100
On Fri, 12 Mar 2004, Rolf Magnus wrote:
> Igor.Smirnov@cern.ch wrote:
>
> > Hi,
> >
...
> > Thus the problem is finding the reliable, portable, fast and simple
> > way for a member function to determine whether the global object to
> > which it belongs has already been initialized or not yet.
>
> A non-static member function must never be called without a completely
> initialized object.
Funny, but I always did that and had no problems.
Anyway, you don't need that. This is a classic
> situation to which the solution is a singleton class.
>
> class MyClass
> {
> public:
> static MyClass& instance()
> {
> static MyClass inst;
> return inst;
> }
> private:
>
> // make instances of the class uncopyable
> MyClass(const MyClass&);
> MyClass& operator=(const MyClass&);
> };
>
> You can just write a default constructor now that does all the
> initialization. Just make it private. Later, you can use the singleton
> through the instance() function, like:
>
> MyClass::instance().doSomething();
>
>
Does this mean that there may be only one such object. Though now it does
not seem to be a problem for me, but it general?
But thank you for this idea! I guess it is portable for Linux, Windows
etc.
--
- Next message: Hattuari: "Re: How did C++ beat the competition?"
- Previous message: Claudio Puviani: "Re: How did C++ beat the competition?"
- In reply to: Rolf Magnus: "Re: Verification of initialization of global objects???"
- Next in thread: Howard: "Re: Verification of initialization of global objects???"
- Reply: Howard: "Re: Verification of initialization of global objects???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|