* Pointer-to-member Strange behaviour
@ 1997-12-05 1:33 Benoit Lavigne
1997-12-06 19:59 ` Alexandre Oliva
0 siblings, 1 reply; 2+ messages in thread
From: Benoit Lavigne @ 1997-12-05 1:33 UTC (permalink / raw)
To: egcs
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 |
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Pointer-to-member Strange behaviour
1997-12-05 1:33 Pointer-to-member Strange behaviour Benoit Lavigne
@ 1997-12-06 19:59 ` Alexandre Oliva
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 1997-12-06 19:59 UTC (permalink / raw)
To: Benoit Lavigne; +Cc: egcs
Benoit Lavigne writes:
> The following code won't compile, and I can't figure out why...
> ptm fn; // pointer to member function
> int Execute() {
> return (d_mgr_p->*fn);
If you intend to call invoke the member function, you must add parens:
return (d_mgr_p->*fn());
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-12-06 19:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-05 1:33 Pointer-to-member Strange behaviour Benoit Lavigne
1997-12-06 19:59 ` Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).