V
Victor Bazarov
Ioannis said:Victor said:Examples are what they are, examples. It doesn't necessarily mean you
cannot use placement new with non-POD objects or for "copying".
Is this also guaranteed to work? SomeClass is a non-POD type here:
#include <iostream>
#include <new>
class SomeClass
{
public:
SomeClass() { std::cout<<"Constructor called!\n"; }
~SomeClass() { std::cout<<"Destructor called!\n"; }
void somefunc() const { std::cout<<"somefunc() called!\n"; }
};
int main()
{
using namespace std;
unsigned char *parray= new unsigned char[sizeof(SomeClass)];
SomeClass *pSomeClass= new(parray) SomeClass;
pSomeClass->somefunc();
pSomeClass->~SomeClass();
delete[] parray;
}
Of course it is! What could possibly make you think that it isn't?
V