dog base object
class dog { void bark(); (print : dog) }
and lot of child class dog
class puppy : dog { void bark(); (print : purry) } class puddle : dog { void bark(); (print : puddle) }
put many kinds of child class "vector dogs"
vector<dog *> dogs; dogs.pushback(puppy); dogs.pushback(puddle); dogs.pushback(martiz); dogs.pushback(yok); (auto dog : dogs) { dog->bark(); }
all class print "i dog"
i want downcast automatically origin class.
what best way case?
class dog { virtual void bark(); (print : dog) }
you should set bark virtual void bark , should work
Comments
Post a Comment