class A {
private :
int a ;
public:
A() {
a = 0;
}
A(A &object) {
a = object.a ; // not sure if this is correct
}
};
int main()
{
A obj1;
A obj2 = obj1; // this one
A obj3(obj1); // this one
}
A obj1;
A obj2(obj1); and A obj1=obj2; (what is difference between these statements)
There's no difference between the two. During a declaration statement, the assignment operator will invoke the respective constructor based on the operand on the right-hand side of the assignment operator. For instance: