Hello,
d->bar();
this will call the member function of Derived class...
but, wht is want is.. 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...
this is possible in C# if we declare the derived class member function like as follow...
// In C#
class Base
{
public:
void foo() { std::cout<< "Base::foo" << std::endl; }
virtual void bar() { std::cout<< "Base::bar" << std::endl; }
};
class Derived : public Base
{
public:
void foo() { std::cout<< "Derived::foo" << std::endl; }
new void bar() { std::cout<< "Derived::bar" << std::endl; } <---
};
int main()
{
Derived d;
d.bar(); <---
return 0;
}
Output:
Base::bar();
Bookmarks