1. A a;
A b = a;
2. A a,b;
b = a;
What is the difference between these two operator =?
Does the first one needs a prototype?
In 1, a is default-constructed and b is copy-constructed from a. There is no assignment going on.
In 2, both a and b are default-constructed and then the value of a is assigned to b.
Both of these are not prototypes, instead it is creating objects of class A. In the first case statement A b = a; invokes the copy constructor of A where as the second case A a,b uses the default constructor of A to create objects and then use assignment operator of A for b=a.
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