oop - C++: Copy object data in member function of base class -
suppose have 2 classes a, , b. b derived a. has no data members, b has 2 integer members.
if define method in class a, following:
void copyfrom( const a* other ) { *this = *other; }
and call in child class, integer data member copied?
no. known slicing problem.
this true if overload operator=
in both a
, b
: *this = *other
ever resolve a::operator=(const a&)
or b::operator=(const a&)
being called.
Comments
Post a Comment