"mlimber" <ml*****@gmail. com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Alex Vinokur wrote: I have the following problem.
class Base
{
public:
void (*pfunc) (int) = 0;
This line won't compile. It's neither a static integral constant nor a
pure virtual function, but you seem to have mixed the syntax for the
two.
[snip]
My first message was unlucky. Please ignore it.
Here is problematic program.
====== foo1.cpp ======
struct Base
{
virtual void func (int) = 0;
};
struct Derived : public Base
{
void func (int)
{
// Stuff
}
};
struct Foo
{
void (*pfunc) (int);
Base* p_;
Foo (Base* p) : p_ (p) {}
void doit ()
{
// Here is what I want to reach
pfunc = p_->func;
// ------------------------
// g++ 4.0.1 produces the following error message:
// ............... .........
// error: argument of type 'void (Base::)(int)'
// does not match 'void (*)(int)
// ............... .........
// because func() is _member_ (not static) function
// ------------------------
}
};
int main ()
{
Base* p = new Derived;
Foo foo (p);
delete p;
return 0;
}
=============== =======
Here is a _partial_ solution of the problem.
====== foo2.cpp ======
struct Base
{
virtual void func (int) = 0;
};
struct Derived : public Base
{
void func (int)
{
// Stuff
}
};
struct Foo
{
void (*pfunc) (int);
static Base* p_s;
Foo (Base* p) { p_s = p; }
static void wrapper(int a)
{
p_s->func (a);
}
void doit ()
{
pfunc = wrapper;
}
};
Base* Foo::p_s = 0;
int main ()
{
Base* p = new Derived;
Foo foo (p);
delete p;
return 0;
}
=============== =======
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn