Function pointer to class member function.

T

TBass

Lots of c, new to c++, yada yada yada. You've heard it all before....

Here's my problem:
From the header for a library:

typedef struct loDriver
{
void (*ldSubscribe)(const loCaller *, int count, loTagPair til[]);
....
} loDriver;


class COPCServer
{
void
mysubscribe (const loCaller *, int count, loTagPair* til);
....
};



COPCServer::mServerInit( int lflags )
{

loDriver ld;

ld.ldSubscribe = mysubscribe;

/* compiler error */
/********************************************
* COPCServer.cpp(178) : error C2440: '=' : cannot convert from
'void (__thiscall
* COPCServer::*)(const struct loCaller *,int,struct loTagPair *)'
to 'void (__cd
* ecl *)(const struct loCaller *,int,struct loTagPair [])'
********************************************** /

...
}

I understand that the return types are not the same because the
mysubscribe function is within a class. What I don't know is how to
cast them to the same type.

Any help is greatly appreciated.

Thanks!
TBJ
 
V

Victor Bazarov

TBass said:
Lots of c, new to c++, yada yada yada. You've heard it all before....
[...]

/* compiler error */
/********************************************
* COPCServer.cpp(178) : error C2440: '=' : cannot convert from
'void (__thiscall
* COPCServer::*)(const struct loCaller *,int,struct loTagPair *)'
to 'void (__cd
* ecl *)(const struct loCaller *,int,struct loTagPair [])'
********************************************** /

...

I understand that the return types are not the same because the
mysubscribe function is within a class. What I don't know is how to
cast them to the same type.

Have you tried reading the FAQ? http://www.parashift.com/c++-faq-lite/
Please do. And not just section 33.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top