S
Steffen Jahn
Hi,
I'm looking for a way to get the pointer to a virtual function of
a base class. That is, I want to force an object to call the
virtual function of a base class. A direct call is no problem, but
I can't find a way to get the right function pointer.
Below is a simple example to describe my problem. -- It's only here
to illustrate the problem. My real implementation uses callback
templates. -- Help is highly appreciated.
Thank you!
Steffen
#include <iostream>
using std::endl ;
using std::cerr ;
struct B {
virtual void f() const { cerr << "B" << endl ; }
} ;
struct C : public B {
virtual void f() const { cerr << "C" << endl ; }
} ;
int main(int argc, char *argv[])
{
C *c = new C ;
c->B::f() ; // direct call: prints "B"
void (B::*g)() const = &B::f ;
(c->*g)() ; // prints "C", but I want "B", so how to set up g?
return 0 ;
}
I'm looking for a way to get the pointer to a virtual function of
a base class. That is, I want to force an object to call the
virtual function of a base class. A direct call is no problem, but
I can't find a way to get the right function pointer.
Below is a simple example to describe my problem. -- It's only here
to illustrate the problem. My real implementation uses callback
templates. -- Help is highly appreciated.
Thank you!
Steffen
#include <iostream>
using std::endl ;
using std::cerr ;
struct B {
virtual void f() const { cerr << "B" << endl ; }
} ;
struct C : public B {
virtual void f() const { cerr << "C" << endl ; }
} ;
int main(int argc, char *argv[])
{
C *c = new C ;
c->B::f() ; // direct call: prints "B"
void (B::*g)() const = &B::f ;
(c->*g)() ; // prints "C", but I want "B", so how to set up g?
return 0 ;
}