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
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@gmail.com] Sent: Monday, July 24, 2006 12:49 AM To: boost-users@lists.boost.org 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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
bringiton bringiton
-
Michael Nicolella