Boost logo

Boost Users :

From: Michael Nicolella (boost_at_[hidden])
Date: 2006-07-24 04:23:52


Not sure that this belongs on the boost list, but to allocate an object in
already allocated memory, you use placement new.

#include <new>
...

void* some_memory = ...;

SomeObject* o = new (some_memory) SomeObject;

-----Original Message-----
From: bringiton bringiton [mailto:kneeride_at_[hidden]]
Sent: Monday, July 24, 2006 12:49 AM
To: boost-users_at_[hidden]
Subject: [Boost-users] manually calling constructor?

Is it possible to manually call the constructor of an object. It is possible
to call the destructor (a trick i found from
std::vector<T>::pop_back())

I stepped through the std::vector<T>::push_back() to find how they call the
constructor for memory that has already been allocated, but I could not
follow the code.

Test3 t;
t.~Test3(); // OK
t.Test3(); // compile error
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net