POV-Ray : Newsgroups : povray.off-topic : C++ destructor question : Re: C++ destructor question Server Time
3 Sep 2024 21:14:58 EDT (-0400)
  Re: C++ destructor question  
From: Warp
Date: 5 Aug 2010 16:04:28
Message: <4c5b194c@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> When an object is stuck into a standard collection in C++, and then the 
> collection goes out of scope, what order is defined on the destructors of 
> the things in the collection? I wouldn't imagine it's the order they were 
> inserted (at least for a random-access type collection).  Does a stack 
> destruct in a different order than a queue does, for example? Does a vector 
> always destruct on increasing indexes?  (An array doesn't call the 
> destructors of its element, does it?)

  Funny, I have never thought of that. If I had to guess, I'd say that
the standard leaves it up to the implementation.

  Arrays (either stack-allocated or dynamically allocated with 'new') are,
however, guaranteed to be constructed in the order of increasing indexes
and destroyed in the reverse order.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.