Overloading a virtual function in a child class

前端 未结 6 1657
一向
一向 2021-01-08 01:04

I am just testing with virtual keyword and inheritance concepts in c++. I have written a small program:

#include
#include

us         


        
6条回答
  •  失恋的感觉
    2021-01-08 01:26

    If you REALLY MUST do it like this, i.e. have a pointer to one class and initialise as a derived class, there's no choice but to always cast the pointer to the correct type when using it. In this case, ((cna_bsc*)_mo)->print(5);

提交回复
热议问题