I need to send method as parameter (MS Visual Studio 2008):
void Apply(Node<string>* node, void (visit(TreeEditor* self, Node<string> *)))
but this error occurs:
error C2664: ‘TreeEditor::Apply’ : cannot convert parameter 2 from ‘void (__thiscall TreeEditor::* )(TreeEditor *,Node *)’ to ‘void (__cdecl *)(TreeEditor *,Node *)’ d:\ed7\saod\labs\oopkkrtree\treeeditor\treeeditor.h 74
I tried to use this type:
void Apply(Node<string>* node, void(__thiscall TreeEditor::*)(TreeEditor *,Node<string> *))
and now it works, but I don’t know how to specify the name of the parameter (for ex: void(func(int)))
I can’t send static method.
I tried to do this:
void Apply(Node<string>* node, void(visit)(__thiscall TreeEditor::*)(TreeEditor *,Node<string> *))
void Apply(Node<string>* node, void(visit(__thiscall TreeEditor::*)(TreeEditor *,Node<string> *)))
void Apply(Node<string>* node, void(__thiscall TreeEditor::*)(visit(TreeEditor *,Node<string> *)))
but it didn’t work.
Please help me.
The name goes after the
*:The
__thiscallis unnecessary and will only work on Visual C++ (IIRC). Also you’ll need to pass or otherwise appropriate aTreeEditorto call the method on.I would also recommend providing a
typedeffor that callback type:Then you can write
Applylike this: