Ferenck

I have this code:

typedef void (*DevRespPointer) (BlueDevice __gc*);

class InternalBlueManager : public CBtIf
{
public:
DevRespPointer DeviceRespondedDelegate;

InternalBlueManager(void)
{
}

~InternalBlueManager(void)
{
}

//Implementacion de Funciones Virtuales Heredadas

void OnDeviceResponded (BD_ADDR bda, DEV_CLASS devClass, BD_NAME bdName, BOOL bConnected)
{

if (DeviceRespondedDelegate!=0)
{
BlueDevice *bd = new BlueDevice(bda, devClass, bdName);
DeviceRespondedDelegate(bd);
}
}

};


/////////////////////////////////////////////


public __gc class BlueManager
{

private: //Miembros Privados
InternalBlueManager * blue;


public: // Funciones Publicas

BlueManager(void)
{
blue = new InternalBlueManager();

}

~BlueManager(void)
{

}

void SetDelegates()
{
blue->DeviceRespondedDelegate = OnDeviceResponded;
}

private: //Funciones Privadas

void OnDeviceResponded(BlueDevice __gc *device)
{
// Do Something;
}

};

If I compile this I get this error message on the red line:
error C2440: '=' : cannot convert from 'void (__clrcall BlueClasses::BlueManager::* )(BlueClasses::BlueDevice __gc *)' to 'BlueClasses:: DevRespPointer'


If I change the red line for
blue->DeviceRespondedDelegate = &OnDeviceResponded;
I get this error:
error C2276: '&' : illegal operation on bound member function expression

If I change it for
blue->DeviceRespondedDelegate = &BlueManager:: OnDeviceResponded;
I get this error:
error C3374: managed function 'BlueClasses::BlueManager:: OnDeviceResponded' requires argument list.

And if I change it for
blue->DeviceRespondedDelegate = &(BlueManager:: OnDeviceResponded);
I get this error again:
error C2276: '&' : illegal operation on bound member function expression.

I'm compiling it with Visual Studio 2003, Framework 1.1

I've tried all what I have seen on forums and manuals and it doesn't work. Somebody knows what am I doing wrond and, how can I solve it

Ferenck



Re: Visual C++ General Pointer to member functions in VS C++ 2003

einaros

I haven't got VC2003 handy, so I can't put this to the test, and neither did I spend too much time with the old Managed C++ syntax, but according to error C2843: You cannot take the address of a non-static data member or method of a managed type.






Re: Visual C++ General Pointer to member functions in VS C++ 2003

Ferenck

Ok, what you said is that there is no way I can point a function pointer to a member function




Re: Visual C++ General Pointer to member functions in VS C++ 2003

Asif110

How have you defined DeviceRespondedDelegate



Re: Visual C++ General Pointer to member functions in VS C++ 2003

einaros

Ferenck wrote:
Ok, what you said is that there is no way I can point a function pointer to a member function

If we're to believe what that error says: yes, as long as it's not static, you cannot take the address of it. There may very well be some delegate type classes in .NET 1.1 (if that's what you're using), but I'm not familar with them, nor how they are used with the old syntax. If you want to solve this quicker, make the function static and pass an instance pointer to it when you invoke the function pointer.






Re: Visual C++ General Pointer to member functions in VS C++ 2003

Ferenck

typedef void (*DevRespPointer) (BlueDevice __gc*);
DevRespPointer DeviceRespondedDelegate;




Re: Visual C++ General Pointer to member functions in VS C++ 2003

Ferenck

The problem is: I can't make the function static because I need to access an instance variable of the class in the function.