I have some struct:
struct A
{
const char* name_;
A* left_;
A* right_;
A(const char* name):name_(name),
left_(nullptr),
right_(nullptr){}
A(const A&);
//A(const A*);//ToDo
A& operator=(const A&);
~A()
{
/*ToDo*/
};
};
/*Just to compile*/
A& A::operator=(const A& pattern)
{
//check for self-assignment
if (this != &pattern)
{
void* p = new char[sizeof(A)];
}
return *this;
}
A::A(const A& pat)
{
void* p = new char[sizeof(A)];
A* tmp = new (p) A("tmp");
tmp->~A();
delete tmp;//I WONDER IF HERE I SHOULD USE DIFFERENT delete[]?
}
int _tmain(int argc, _TCHAR* argv[])
{
A a("a");
A b = a;
cin.get();
return 0;
}
Guys I know this is far from ideal and far from finished. But please don't tell me the answer how to do it properly. I'm trying to figure it out myself. The only think I would like to know if I'm deleting my memory in proper way.
Thanks.
This is the link to different question which is really important to me