
Originally Posted by
kunalnandi
member function of Derived class Derived::bar() should be hidden from the derived class object.... and the object of Derived class should called Base::bar() member function...
Are you talking about this?
#include <iostream>
class Base
{
public:
void foo() { std::cout << "Base::foo" << std::endl; }
void bar() { std::cout << "Base::bar" << std::endl; }
};
class Derived : public Base
{
public:
void foo() { std::cout << "Derived::foo" << std::endl; }
};
int main()
{
Derived d;
d.foo();
d.bar(); // <--
return 0;
}
#include <iostream>
class Base
{
public:
void foo() { std::cout << "Base::foo" << std::endl; }
void bar() { std::cout << "Base::bar" << std::endl; }
};
class Derived : public Base
{
public:
void foo() { std::cout << "Derived::foo" << std::endl; }
};
int main()
{
Derived d;
d.foo();
d.bar(); // <--
return 0;
}
To copy to clipboard, switch view to plain text mode
Output:
Derived::foo()
Base::bar()
Bookmarks