Overloading a virtual function in a child class

前端 未结 6 1686
一向
一向 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-08 01:32

    Once you overload a function from Base class in Derived class all functions with the same name in the Base class get hidden in Derived class.

    Once you added the function cna_bsc::print(int a) to your derived class the function cna_MO::::print() is no longer visible to users of the Derived class. This is known as function hiding.

    Solution: In order to make the hidden function visible in derived class, You need to add:

    using cna_MO::print;
    

    in the public section of your derived class cna_bsc.

    Good Read:

    What's the meaning of, Warning: Derived::f(char) hides Base::f(double)?

提交回复
热议问题