Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c+中的方法类型+;_C++_Visual Studio 2008 - Fatal编程技术网

C++ c+中的方法类型+;

C++ c+中的方法类型+;,c++,visual-studio-2008,C++,Visual Studio 2008,我需要将方法作为参数发送(MS Visual Studio 2008): void应用(Node*Node,void(访问(TreeEditor*self,Node*)) 但出现这种错误: 错误C2664:“TreeEditor::Apply”:无法将参数2从“void(\uu thiscall TreeEditor::*)(TreeEditor*,Node*)”转换为“void(\uu cdecl*)(TreeEditor*,Node*)”d:\ed7\saod\labs\oopkkrtre

我需要将方法作为参数发送(MS Visual Studio 2008):

void应用(Node*Node,void(访问(TreeEditor*self,Node*))
但出现这种错误:

错误C2664:“TreeEditor::Apply”:无法将参数2从“void(\uu thiscall TreeEditor::*)(TreeEditor*,Node*)”转换为“void(\uu cdecl*)(TreeEditor*,Node*)”d:\ed7\saod\labs\oopkkrtree\TreeEditor\TreeEditor.h 74

我尝试使用这种类型:

void Apply(Node<string>* node, void(__thiscall TreeEditor::*)(TreeEditor *,Node<string> *))
void Apply(Node*Node,void(\uu thiscall TreeEditor::*)(TreeEditor*,Node*))
现在它可以工作了,但我不知道如何指定参数的名称(对于ex:void(func(int)))

我无法发送静态方法

我试着这样做:

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> *)))
void Apply(Node*Node,void(visit)(\uu thiscall TreeEditor::*)(TreeEditor*,Node*))
void Apply(Node*Node,void(访问(\u thiscall TreeEditor::*)(TreeEditor*,Node*))
void Apply(Node*Node,void(\uu thiscall TreeEditor::*)(访问(TreeEditor*,Node*))
但它不起作用。
请帮帮我。

名字在
*
后面:

void Apply(Node<string>* node, void(TreeEditor::*visit)(TreeEditor *,Node<string> *))
然后您可以这样编写
Apply

void Apply(Node<string>* node, TreeEditorVisitor visit)
void应用(节点*Node,树编辑器访问者访问)

默认情况下,\uu this调用表示该函数是类成员函数,\uu cdecl是非成员函数。因此,您的错误消息是,您的函数声明请求了一个非成员函数指针,但您正在传入一个成员函数指针

因此,您可以更改应用的声明

void Apply(Node<string>* node, void (TreeEditor::*visit)(TreeEditor* self, Node<string> *))
void应用(Node*Node,void(TreeEditor::*visit)(TreeEditor*self,Node*))

或者使用一个调用对象方法的包装函数,并将该函数传入。

谢谢。但是当我尝试调用这个方法,比如:visit(this,node)或visit(node),我得到了这样一个错误:term不计算一个取2(1)的函数arguments@Str必须以特殊方式调用方法指针:
(this->*visit)(节点)
(如果
this
是指向要调用
visit
树编辑器的指针)。如果此答案回答了您的问题,请单击旁边的复选标记接受。
void Apply(Node<string>* node, TreeEditorVisitor visit)
void Apply(Node<string>* node, void (TreeEditor::*visit)(TreeEditor* self, Node<string> *))