Checking for dynamically allocated memory in copy constructors
I'm trying to write a copy constructor that needs to throw the memory Allocation error exception if no dynamic memory is available. I have only overloaded the = operator but do not want to overload the == operator. I am receiving errors and would appreciate any help. Thanks.
Code:
dynamicInt::dynamicInt(const dynamicInt& obj)
{
if(obj==NULL)
{
cerr<<"Memory allocation error";
exit(1);
}
*ptr = obj.getData();
}
The error I get is: error C2676: binary '==' : 'const class dynamicInt' does not define this operator or a conversion to a type acceptable to the predefined operator