While copying the objects if you say X a = b and asssume that '=' operator is overloaded then what it will call, a copy constructor or operator overloading function
while doing X a=b; in this statement what it will do first create the object 'a' then it will copy the value of 'b' to ' a'. so the copy constructure will call.
Rahul Vij
Feb 1st, 2006
X a=b is internally represented as X a(b). The compiler will call a copy constructor and not the overloaded = operator. as for theoperator to be called the LHS object should have been instantiated before the call. but in the above case it is getting instantiated in the same call. so copy constructor will be called doing a shallow copy. a standard one will be generated by the compiler only
vijay saxena
Oct 23rd, 2006
constructor will first call. becs this function invoked when new object is created so it first look for constructor rather than go for operator overloading.
vijay
Sunny
May 7th, 2007
Definitly the constructor should be invoked, but can "=" be overloaded ? i doubt it cannot.
While copying the objects if you say X a = b and asssume that '=' operator is overloaded then what it will call, a copy constructor or operator overloading function