W
wink
I'd like to determine if a method has been overridden as was asked
here:
http://www.velocityreviews.com/foru...class-overrides-a-virtual-memberfunction.html
The answer was can't do it, but I thought I'd ask here, my test code
is:
#include <iostream>
class B {
public:
B() {}
~B() {}
virtual void m() {}
};
class A : public B {
public:
A() {}
~A() {}
virtual void m() {}
};
void test(const B &r) {
if (&r.m == &B::m) {
// do something not overridden
std::cout << "not overridden" << std::endl;
} else {
// do something else was overridden
std::cout << "overridden" << std::endl;
}
}
int main(int argc, char *argv[]) {
A a;
B b;
test(b);
test(a);
return 0;
}
The compiler (gcc 4.0.3) complains:
tor.cc: In function 'void test(const B&)':
tor.cc:22: error: ISO C++ forbids taking the address of a bound member
function to form a pointer to member function. Say '&B::m'
Any suggestions on how this can be done?
Thanks
-- Wink Saville
here:
http://www.velocityreviews.com/foru...class-overrides-a-virtual-memberfunction.html
The answer was can't do it, but I thought I'd ask here, my test code
is:
#include <iostream>
class B {
public:
B() {}
~B() {}
virtual void m() {}
};
class A : public B {
public:
A() {}
~A() {}
virtual void m() {}
};
void test(const B &r) {
if (&r.m == &B::m) {
// do something not overridden
std::cout << "not overridden" << std::endl;
} else {
// do something else was overridden
std::cout << "overridden" << std::endl;
}
}
int main(int argc, char *argv[]) {
A a;
B b;
test(b);
test(a);
return 0;
}
The compiler (gcc 4.0.3) complains:
tor.cc: In function 'void test(const B&)':
tor.cc:22: error: ISO C++ forbids taking the address of a bound member
function to form a pointer to member function. Say '&B::m'
Any suggestions on how this can be done?
Thanks
-- Wink Saville