This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Pointer-to-member Strange behaviour
- To: egcs at cygnus dot com
- Subject: Pointer-to-member Strange behaviour
- From: Benoit Lavigne <blavigne at newbridge dot com>
- Date: Fri, 05 Dec 1997 00:25:16 -0500
The following code won't compile, and I can't figure out why...
class Test {
public:
int fn0();
};
int Test::fn0() {
return 0;
}
class mgr_Param {
protected:
Test* d_mgr_p; // Manager object pointer
public:
mgr_Param(Test *mgr_p) : d_mgr_p(mgr_p) { }
virtual int Execute() = 0;
};
// Convenient typedef
typedef int (Test::* ptm)();
class mgr_Param0 : public mgr_Param
{
protected:
ptm fn; // pointer to member function
public:
mgr_Param0(Test* m_p, ptm f) : mgr_Param(m_p), fn(f) { }
int Execute() {
return (d_mgr_p->*fn);
}
};
mgr_Param* CreateParam(Test* mgr_p, ptm f)
{
return(new mgr_Param0(mgr_p, f));
}
int main() {
mgr_Param* t1;
Test test;
t1 = CreateParam(&test, &Test::fn0);
t1->Execute();
};
gcc-2.7.2.3 gives:
test1.cc: In method `int mgr_Param0::Execute()':
test1.cc:51: Internal compiler error 308.
test1.cc:51: Please submit a full bug report to
egcs-1.0 (great work by the way!):
test1.cc: In method `int mgr_Param0::Execute()':
test1.cc:51: warning: assuming & on `(*mgr_Param::d_mgr_p) .*
mgr_Param0::fn'
test1.cc:51: sorry, not implemented: address of bound pointer-to-member
expression
What I want to do:
Call a function on a class instance, with a given set of parameters.
The original code is templatized to handle the arbitrary case:
Class instance;
t1 = CreateParam(&instance, &Class::SomeFunc, FuncP1 p1, ...pn);
t1->Execute() // does instance->SomeFunc(p1, ... pn);
--
| Benoit Lavigne, Newbridge Networks Corporation |
| 600 March Road, Kanata, Ontario, Canada, K2K 2E6 |
| Voice: (613)780-3535 ext. 3185 |
| e-mail:blavigne@Newbridge.COM |