Can someone verify my code for copy constructor and assigment operator?
Having a problem with delete in the destructor,I assume I am going wrong somewhere,Can some one highlight the problem.
-----------------------------------------------------------------------------
class hello
{
char *name;
public:
hello(char *s)
{
name = new char[10];
strcpy(name,s);
cout<<"Default constructor.\n";
}
hello(const hello &h)
{
name = new char[10];
strcpy(name,h.name);
cout<<"In the copy constructor.\n";
cout<<" the name is "<<name;
}
hello &operator = (const hello &i)
{
name = i.name;
cout<<"In assignment operator"<<endl;
cout<<"Name is "<<name<<"\n";
return *this;
}
~hello()
{
//delete name;
cout<<"In the destructor/n";
}
};
int main()
{
hello h("Welcome");
hello g = h;
hello p("Application");
p = h;
return 0;
}