i know you can make two objects equal to each other when one of them is being declared. i tested this in my program. but when i went to use a assignment statement it freaked out. Can you make two objects equal to each other with a assignment statement or can you only do that when one object is being declared?
You have provide operator= to a class so as copy the contents of another object. For example:
class A
{
public:
//Default constructor
A();
//Copy constructor
A(const A&);
//Assignment operator
A& operator=(const A& a);
};
int main()
{
A a; //Invokes default constructor
A b(a); //Invokes copy constructor;
A c;
c = a; //Invokes assignment operator
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With