Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.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++_Templates_Function Pointers - Fatal编程技术网

C++ 将对象和成员函数作为参数传递

C++ 将对象和成员函数作为参数传递,c++,templates,function-pointers,C++,Templates,Function Pointers,我试图创建一个模板函数,它调用一个类的成员函数 template<typename T> void call(T owner, void (T::*func)()) { (owner.func()); } 但是编译器返回错误C2664。 有什么问题吗?func是指向成员函数的指针;调用它们有一种特殊的语法: (owner.*func)(); (owner.*func)();

我试图创建一个模板函数,它调用一个类的成员函数

template<typename T>
void call(T owner, void (T::*func)())
{
    (owner.func());
}
但是编译器返回错误C2664。
有什么问题吗?

func
是指向成员函数的指针;调用它们有一种特殊的语法:

(owner.*func)();
(owner.*func)();