c++ - Downcasting and Virtual Functions -
i asked question in interview , unsure of behaviour in following case :
class { virtual fun1(){...} virtual fun2(){...} }; class b : public { virtual fun1(){...} virtual fun2(){...} }; now if,
a* aobj = new a; b* bobj = (b*) aobj; does bobj have access b's methods because of virtual keyword or not because it's pointing object of aobj ?
can me how downcasting affects access ?
assigning address of base-class object derived-class pointer undefined behavior. can happen: calling bobj's functions can invoke b's functions, can invoke a's functions, can crash program, or format hard drive. depend on compiler , optimization options.
Comments
Post a Comment