well if you want to keep it public, dont declare it virtual.
EDIT: Srikanth commented wondering about overriding a private member function in a derived class.
class A
{
public:
virtual ~A(){};
void test()
{
foo();
};
private:
virtual void foo()
{
std::cout << "A";
};
};
class B : public A
{
public:
virtual void foo()
{
std::cout << "B";
};
};
void test()
{
B b;
A& a = b;
a.test(); // this calls the derived B::foo()
return 0;
}`