c++ - Is there a way to call base class function which is over-rided in its derived class that used private inheritance? -
i'm going through inheritance concepts in c++ , tried such code:
class base{ public: void display(int j) { cout<<j<< " base "<<endl; } }; class derived:private base{ public: using base::display; void display(int k) { cout<<k<< " derived "<<endl; } }; int main() { derived obj; obj.display(10); //obj.base::display(46); --> cannot used base privately inherited. conversion derived base cannot happen in case. return 0; }
in above case, there way invoke base class display
function main using obj
in anyway?
if base function not over-rided in derived class, using
(in case if base functions hidden overloaded functions in derived), declare in derived , invoke derived class obj
. in such cases base function over-rided in derived private inheritence, there way invoke base function?
as i'm learning c++, i'm curious know if there way thing (irrespective of practical use case).
not directly, because function in base class private in derived class, , using declaration doesn't here. can add function derived class, different name, calls base function. no comment on design issues lead complexity.
Comments
Post a Comment