D
Dave
Hello NG,
In a thread I had started a long time ago, the conclusion had been reached
that there is no good way to select between calling const vs non-const
methods of the same name. (Of course, the object in question is non-const
so that both may be legally called.) However, it appears I have indeed
found a way to do it. I'm sure hoping nobody can poke any holes in my
little scheme, but I want to throw it out there to see if it stands up to
scrutiny. Please see the sample program included below...
Thanks,
Dave
#include <iostream>
using namespace std;
class foo
{
public:
void f() {cout << "non-const" << endl;}
void f() const {cout << "const" << endl;}
};
int main()
{
void (foo::*pm1)() = &foo::f;
void (foo::*pm2)() const = &foo::f;
foo a;
(a.*pm1)(); // Call the non-const f()
(a.*pm2)(); // Call the const f()
}
In a thread I had started a long time ago, the conclusion had been reached
that there is no good way to select between calling const vs non-const
methods of the same name. (Of course, the object in question is non-const
so that both may be legally called.) However, it appears I have indeed
found a way to do it. I'm sure hoping nobody can poke any holes in my
little scheme, but I want to throw it out there to see if it stands up to
scrutiny. Please see the sample program included below...
Thanks,
Dave
#include <iostream>
using namespace std;
class foo
{
public:
void f() {cout << "non-const" << endl;}
void f() const {cout << "const" << endl;}
};
int main()
{
void (foo::*pm1)() = &foo::f;
void (foo::*pm2)() const = &foo::f;
foo a;
(a.*pm1)(); // Call the non-const f()
(a.*pm2)(); // Call the const f()
}