What's the difference between a derived object and a base object in c++?

前端 未结 10 1823
一个人的身影
一个人的身影 2021-01-01 06:23

What\'s the difference between a derived object and a base object in c++,

especially, when there is a virtual function in the class.

Does the derived object

10条回答
  •  被撕碎了的回忆
    2021-01-01 06:52

    Are you asking about the respective objects' representation in memory?

    Both the base class and the derived class will have a table of pointers to their virtual functions. Depending on which functions have been overridden, the value of entries in that table will change.

    If B adds more virtual functions that aren't in the base class, B's table of virtual methods will be larger (or there may be a separate table, depending on compiler implementation).

提交回复
热议问题