By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Function pointer to class member function.

P: n/a
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

Jun 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
TBass wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 21 '06 #2

P: n/a
[snip]
Have you tried reading the FAQ? http://www.parashift.com/c++-faq-lite/
[/snip]

Thanks! I was not aware of the FAQ. I will read it now.

Jun 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.