Article View: comp.os.ms-windows.nt.misc
Article #5Problem with callback methods
From: Jeff Sumner
Date: Wed, 23 Aug 1995 20:48
Date: Wed, 23 Aug 1995 20:48
63 lines
2540 bytes
2540 bytes
I'm having a problem with the Microsoft Visual C++ compiler (V2.1 on
NT). I'm trying to create an object that is capable of having
callback methods registered with it. When certain actions take place,
the Caller object will call back the methods registered from the
SubClass class. I have working code on OS/2 using IBM's CSet++
compiler, but I get an odd syntax error when I try to compile the code
under VC++.
Here's a very simplified piece of my code (I've removed everything
that's not necessary to demonstrate the error):
class BaseClass
{
public:
typedef int (BaseClass::*CBM)();
};
class Caller
{
public:
virtual int regCallBack( BaseClass::CBM cbM );
};
class SubClass : public BaseClass
{
public:
SubClass();
int fnCallBack();
};
static Caller* pobCaller;
static SubClass* pobSubClass;
SubClass::SubClass()
{
pobCaller->regCallBack( (BaseClass::CBM)&(SubClass::fnCallBack) );
// The above line generates the following error message:
// bug.c(25) : error C2276: '&' : illegal operation on bound member
// function expression
}
void main( void )
{
pobCaller->regCallBack( (BaseClass::CBM)&(SubClass::fnCallBack) );
// The above line compiles cleanly
}
As you can see, the code in SubClass::SubClass() and main() is
identical, however the code in SubClass generates an error. As I
said, this code compiles and works under CSet++, so I really don't see
what the problem could be.
I'd appreciate any help anyone can give me. If possible, please email
your replies to jeffs@linkage.com - I'll summarise the responses.
Thanks in advance!
+---------------------+-------------------+-------------------------+
|Jeff Sumner | |JeffS@Toronto.LinkAge.com|
|LinkAge Software, Inc| | Toronto, Ontario, Canada|
+---------------------+-------------------+-------------------------+
|Any opinions expressed are, in fact, beamed into my brain by aliens|
+-------------------------------------------------------------------+
Technical Details
Message-ID:
<DDs75L.pCK@LinkAge.com>Path:
arc1-ca.pugleaf.net!news.uunet.ca!linkage!newsShow Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.nt.misc,comp.lang.c++ Path: arc1-ca.pugleaf.net!news.uunet.ca!linkage!news From: JeffS@LinkAge.com (Jeff Sumner) Subject: Problem with callback methods Sender: news@LinkAge.com (News Administrator) Message-ID: <DDs75L.pCK@LinkAge.com> Date: Wed, 23 Aug 1995 20:48:57 GMT Reply-To: JeffS@LinkAge.com (Jeff Sumner) Organization: LinkAge Software, Inc. X-Newsreader: IBM NewsReader/2 v1.2 Followup-To: JeffS@LinkAge.com