Quote Originally Posted by jacek View Post
What do you mean exactly by "hidden from the base MyBaseC"? But it seems that you just want the default behaviour of non-virtual methods:
Qt Code:
  1. #include <iostream>
  2.  
  3. class Base
  4. {
  5. public:
  6. void foo() { std::cout<< "Base::foo" << std::endl; }
  7. virtual void bar() { std::cout<< "Base::bar" << std::endl; }
  8. };
  9.  
  10. class Derived : public Base
  11. {
  12. public:
  13. void foo() { std::cout<< "Derived::foo" << std::endl; }
  14. virtual void bar() { std::cout<< "Derived::bar" << std::endl; }
  15. };
  16.  
  17. int main()
  18. {
  19. Derived d;
  20. Base *b = &d;
  21.  
  22. d.foo();
  23. b->foo(); // <--
  24.  
  25. d.bar();
  26. b->bar();
  27.  
  28. return 0;
  29. }
To copy to clipboard, switch view to plain text mode 

Output:
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();