Original Post
I’ve spend hours upon hours trying find out what is wrong with a program I am doing and I finally narrowed it down to using a destructor with a placement new. Whenever I have a class with a destructor I always get the wrong pointer returned when I try to use a placement new on it. Here is some code that illustrates my problem: -------results--------- first pointer:00420400 second pointer:00420404 Press any key to continue ------------------------ Is there anyway around this or am I going to have to quit using destructors?
#include <iostream>
using namespace std;
class cBlah{
private:
int x[10];
public:
cBlah()
{
for(int i=0;i<10;i++)
{
x=i;
}
}//end constructor
~cBlah()
{
}// end destructor
};// END CLASS
int main(int argc, char** argv)
{
cBlah *pBlah= (cBlah*) malloc(sizeof(cBlah)*3);
cBlah *pBlah2;
cout<<"first pointer:"<<pBlah<<endl;
pBlah2=new(pBlah) cBlah[3];
cout<<"second pointer:"<<pBlah2<<endl;
return 0;
}