I am using the pimpl idiom and want to reference one of the methods of the forward declared class. Below isn't exactly what I'm doing but uses the same concepts.
template< typename Class, void (Class::*Method)(void) >
struct Call
{
Call( Class* c )
: m_c(c)
{ }
void operator()( void )
{
(m_c->*Method)();
}
Class* m_c;
};
class A
{
public:
void foo( void )
{
std::cout << "A::foo\n";
}
};
// this works
void do_foo( A* a )
{
Call<A,&A::foo> c(a);
c();
}
class B;
// this doesn't compile
extern void B::bar( void );
// this is what i'd ultimately like to do
void do_bar( B* b )
{
Call<B,&B::bar> c(b);
c();
}
Two questions:
- Can this be done?
- Why can't it be done?