Hi,
I am trying to implement some kind of callback between classes…so the children have a pointer to a parent class.
I want it to pass events to the parent
So I have something like the following…and i have got an error…how can I send a function pointer from parent to children?
//***********************A.h
#include "B.h"
class A
{
public:
A(){
b_object = new B();
b_object->set_callback(b_callback); //****error
}
~A(){b_object = nullptr;}
void b_callback(Component* listenercomponent, String typeoflistener) {
//Do something as add it as listener: listenercomponent->addlistener(this);
}
private:
ScopedPointer<B> b_object;
}
//*********************B.h
class B{
{
public:
B(){
//init whatever...buttons, and so on
}
~B(){
pointer_callback = nullptr;
};
void set_callback(void(*x)(Component *listenercomponent, String typeoflistener)) {
pointer_callback = x;
}
private:
void(*pointer_callback)(Component *listenercomponent, String typeoflistener);
}
//*******************************************
ERROR in Visual Studio: (Note: “eth_panel” would be “A” in the example;
Severity Code Description Project File Line Suppression State
Error C2664 ‘void table_dev::set_gui_listbox_callback(void (__cdecl *)(juce::Component ,juce::String))’: cannot convert argument 1 from 'void (__thiscall eth_panel:: )(juce::Component *,juce::String)’ to ‘void (__cdecl *)(juce::Component *,juce::String)’ Eth1 c:\carlosm\electronica\2-sw\juce\projects\eth1\source\eth_panel_gui.cpp 88
JUCE ERROR pop up WARNING:: argument of type “void(A::)()” is //incompatible with “void(A*)()”




