I have a simple question.. Can i allocate and deallocate memory like this in the operator+ for other object
delete [] p.name;
p.name = new char[strlen(a.name) + 1];
Look at the operator+
class PlDrustvo{
private:
char *name;
public:
// Constructors and destructors are implemented.
PlDrustvo operator+(const PlDrustvo &a)
{
PlDrustvo p(*this);
if(///////){
delete [] p.name;
p.name = new char[strlen(a.name) + 1];
strcpy(p.name, a.name);
}
return p;
}
};