lundi 29 avril 2019

why child object can be assigned to base but not base to child, how it differs when two class are differ different [duplicate]

This question already has an answer here:

As c++ standard says,

copy assignment is implicitly declared if not declared by user,

If this is the case, when we declare two class one is base and one child , then for both class "copy assignment" is declared. So if its true then

when

 Base b;
    child c;
    b = c // success (but according to me it should failed)
    c = b // error 

(why its failure , as c is inheriting b , then it should have both assignment operator overloaded function). many place its explained like animal and dog example , buts not the technical prospective view.

Aucun commentaire:

Enregistrer un commentaire