One way to do what you want is to declare a function ptr to each function. Then you can use the pointers to call whichever function you want.
Code:
#include <iostream>
using namespace std;
class B
{
};
class C
{
public:
void get()
{
cout<<"non-const get() called"<<endl;
}
void get() const
{
cout<<"const get() called"<<endl;
}
};
int main()
{
C nonConstMyC;
nonConstMyC.get(); //calls non-const get()
const C constMyC;
constMyC.get(); //calls const get()
cout<<endl;
cout<<"Non-const C object used to call both functions:"<<endl;
//Declare a pointer to the const get():
void (C::*ptrConstGet)() const = C::get;
//Use the non-const C to call the const get():
(nonConstMyC.*ptrConstGet)();
//Declare a pointer to the non-const get():
void (C::*ptrNonConstGet)() = C::get;
//Use the non-const C to call the non-const get():
(nonConstMyC.*ptrNonConstGet)();
return 0;
}
Actually, you only need to declare one function pointer: a pointer to the const get(). Then, you can call both functions like this:
Code:
nonConstMyC.get();
(nonConstMyC.*ptrConstGet)()