Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static object/variable

Reply
Thread Tools

static object/variable

 
 
junw2000@gmail.com
Guest
Posts: n/a
 
      01-23-2008
Is it possible to destruct a static object or variable before the
program terminate?

Thanks
 
Reply With Quote
 
 
 
 
Sebastian Redl
Guest
Posts: n/a
 
      01-23-2008
wrote:

> Is it possible to destruct a static object or variable before the
> program terminate?


You can call the destructor explicitly, but it will be called again when the
program terminates, so no, I wouldn't advise you to do that.

If you have to, use something pointer-like and use new and delete for
explicit allocation/de-allocation.

E.g. a boost::scoped_ptr or a std::auto_ptr or even a boost:ptional.
(Doesn't use the heap.)

--
Sebastian Redl
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-23-2008
wrote:
> Is it possible to destruct a static object or variable before the
> program terminate?
>

Possible, yes. Desirable, no. The object will be destroyed twice.

Maybe you want a singleton rather than a static object?

--
Ian Collins.
 
Reply With Quote
 
junw2000@gmail.com
Guest
Posts: n/a
 
      01-23-2008
On Jan 22, 11:52 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> junw2...@gmail.com wrote:
> > Is it possible to destruct a static object or variable before the
> > program terminate?

>
> Possible, yes. Desirable, no. The object will be destroyed twice.
>
> Maybe you want a singleton rather than a static object?
>
> --
> Ian Collins.


Singleton is still implemented using static variable, right? What is
the advantage of singleton than static variable?

Thanks.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-23-2008
wrote:
> On Jan 22, 11:52 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>> junw2...@gmail.com wrote:
>>> Is it possible to destruct a static object or variable before the
>>> program terminate?

>> Possible, yes. Desirable, no. The object will be destroyed twice.
>>
>> Maybe you want a singleton rather than a static object?
>>

*Please* don't quote signatures.

> Singleton is still implemented using static variable, right? What is
> the advantage of singleton than static variable?
>

Not necessarily.

There are other ways of implementing a singleton, such as using an
object with a static pointer member.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PIX public/24 ip static mapping means 256 times interfaces static maps? Nieuws Xs4all Cisco 2 05-26-2005 06:25 PM
PIX public/24 ip static mapping means 256 times interfaces static maps? Nieuws Xs4all Cisco 0 05-26-2005 11:07 AM
Static is REALLY Static! Paul W ASP .Net 2 05-03-2005 10:12 AM
Static classes with static members Ben ASP .Net 3 06-01-2004 07:43 PM
Static vs. non-static connection Natan ASP .Net 8 05-26-2004 08:21 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57