I have a class that defines a function pointer type via a typedef. This
class has a member of that function pointer type that gets set via a class
constructor. I would like this class to be able to do call backs to
external functions via this mechanism but am having linking problems. I am
unsure of the correct way to export the class / typedef. Basically, I am
trying to perform c# delegate type functionality. What is the proper way to
define the function pointer and class so they are exported with correct
linkage?
namespace Critical

{

typedef __declspec(dllexport) void (*LogEvent)(LOG_LEVELS level, TCHAR*
detail);

class __declspec(dllexport) CallbackLogger : public LoggerBase

{

private:

CallbackLogger(void); //default constructor

LogEvent m_onLogEvent;


public:

CallbackLogger(LogEvent le);

~CallbackLogger(void);





thanks!

Re: c++ class with member of function pointer type by Igor

Igor
Mon Sep 25 17:59:37 CDT 2006

scott mcfadden <nospam.smcfadden@criticaltech.com> wrote:
> I have a class that defines a function pointer type via a typedef.
> This class has a member of that function pointer type that gets set
> via a class constructor. I would like this class to be able to do
> call backs to external functions via this mechanism but am having
> linking problems. I am unsure of the correct way to export the class
> / typedef. Basically, I am trying to perform c# delegate type
> functionality. What is the proper way to define the function pointer
> and class so they are exported with correct linkage?
> namespace Critical
>
> {
>
> typedef __declspec(dllexport) void (*LogEvent)(LOG_LEVELS level,
> TCHAR* detail);

You cannot use __declspec(dllexport) with a typedef. It does not make
any sense - types don't get exported. A function pointer can point
equally well to an exported or non-exported function, without any
additional qualifiers. Just drop __declspec here.

> class __declspec(dllexport) CallbackLogger : public LoggerBase

What little code you show looks good to me (modulo the correction
above). What specifically seems to be the problem?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: c++ class with member of function pointer type by scott

scott
Mon Sep 25 19:17:06 CDT 2006

Guess, I am unsure on the client side how to declare the function pointer
instance so that it points to another class's member function (non static).

"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:ueucHZP4GHA.4196@TK2MSFTNGP05.phx.gbl...
> scott mcfadden <nospam.smcfadden@criticaltech.com> wrote:
>> I have a class that defines a function pointer type via a typedef. This
>> class has a member of that function pointer type that gets set
>> via a class constructor. I would like this class to be able to do
>> call backs to external functions via this mechanism but am having
>> linking problems. I am unsure of the correct way to export the class
>> / typedef. Basically, I am trying to perform c# delegate type
>> functionality. What is the proper way to define the function pointer
>> and class so they are exported with correct linkage?
>> namespace Critical
>>
>> {
>>
>> typedef __declspec(dllexport) void (*LogEvent)(LOG_LEVELS level,
>> TCHAR* detail);
>
> You cannot use __declspec(dllexport) with a typedef. It does not make any
> sense - types don't get exported. A function pointer can point equally
> well to an exported or non-exported function, without any additional
> qualifiers. Just drop __declspec here.
>
>> class __declspec(dllexport) CallbackLogger : public LoggerBase
>
> What little code you show looks good to me (modulo the correction above).
> What specifically seems to be the problem?
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>



Re: c++ class with member of function pointer type by Igor

Igor
Mon Sep 25 20:59:53 CDT 2006

"scott mcfadden" <nospam.smcfadden@criticaltech.com> wrote in message
news:%23l2hhEQ4GHA.4740@TK2MSFTNGP03.phx.gbl
> Guess, I am unsure on the client side how to declare the function
> pointer instance so that it points to another class's member
> function (non static).

class C;

typedef ReturnType (C::*MemberPointer)(ParamType1, ParamType2);

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: c++ class with member of function pointer type by Alex

Alex
Tue Sep 26 01:43:11 CDT 2006

scott mcfadden wrote:
> I have a class that defines a function pointer type via a typedef. This
> class has a member of that function pointer type that gets set via a class
> constructor. I would like this class to be able to do call backs to
> external functions via this mechanism but am having linking problems. I am
> unsure of the correct way to export the class / typedef. Basically, I am
> trying to perform c# delegate type functionality. What is the proper way to
> define the function pointer and class so they are exported with correct
> linkage?

Look for the thread "Casting of pointer to member functions"
started on 15 Sep 2006 in this group.