c++ - Grandparent overloaded function in child -
i need understand why c++ don't allow access grandparent overloaded functions in kid if of overloaded function declared in parent. consider next example:
class grandparent{ public: void foo(); void foo(int); void test(); }; class parent : public grandparent{ public: void foo(); }; class kid : public parent{ public: child(){ //foo(1); //not accessible test(); //accessible } };
here, 2 functions foo() , foo(int) overloaded functions in grandparent. foo(int) not accessible since foo() declared in parent (doesn't matter if declared public or private or protected). however, test() accessible, right per oop.
i need know reason of behavior.
the reason method hiding.
when declare method same name in derived class, base of operations class methods name hidden. total signature doesn't matter (i.e. cv-qualifiers or argument list).
if explicitly want allow call, can use
using grandparent::foo;
inside parent
.
c++ overloading overriding
No comments:
Post a Comment