class A {
public:
A() {
counter = 0;
}
~A() {
counter++;
std::cout << "~A(): " << counter << std::endl;
}
int counter;
};
int main(int argc, char* argv[])
{
A a;
a.~A();
return 0;
}
>>just look at the include files:i looked at the header, but got a little confused.i don't see how you can call a destruct of a a memory space that still exists. ie a C version of a vector.shared_ptr<int> list[1024];int n = 0;// add an itemshared_ptr<int> newItem(new int(1));list[n++] = newItem;// remove the tail itemn--;// destructor never calledis it possible to call a destructor of an object that exists?what then happens then the object goes out of scope? the destructor will be called twice.(or maybe i am completely missing the point)BTW: not sure if above code compiles (did it in my head)
On 7/10/06, Boris Breidenbach < Boris.Breidenbach@physik.uni-erlangen.de> wrote:On Mon, Jul 10, 2006 at 03:58:19PM +1000, bringiton bringiton wrote:
> This question is based on curiosity. How does std::vector::pop_back() call
> the destructor of the item getting removed?
>
> i understood std::vector to be a contigious array of memory, therefore an
> item's memory does not go out of scope when being popped. ie the item goes
> out of scope when the entire array goes out of scope.
just look at the include files:
bits/stl_vector.h says:
void
pop_back()
{
--this->_M_impl._M_finish;
std::_Destroy(this->_M_impl._M_finish);
}
so the destructor is called in std::_Destroy. Which can be found in
bits/stl_construct.h:
/**
* @if maint
* Destroy the object pointed to by a pointer type.
* @endif
*/
template<typename _Tp>
inline void
_Destroy(_Tp* __pointer)
{ __pointer->~_Tp(); }
It just calls the destructor.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users