operator= in c++ -


possible duplicate:
trouble inheritance of operator= in c++

hello everyone, let's assume have 2 classes:

base{}; //inside have operator= derived{}; //inside don't have operator= 

why 1 working perfectly:

derived der1, der2; der1=der2;  //<-here know calls base::operator= 

and 1 not:

derived der1; base bas1; der1=bas1;  //<-here why can't call base::operator=? 

the implicitly declared copy assignment operator looks like

derived& operator=(const derived&); 

this implicitly declared function calls operator= each base class , member subobject (this why base class operator= overload called).

bas1 of type base, not derived, , there no implicit conversion base derived, hence doesn't work. need declare appropriate assignment operator in order support assigning object of type base object of type derived (this bit unusual though).


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -