【发布时间】:2017-12-07 12:59:22
【问题描述】:
我想知道为什么要把 fun1() 设为静态成员函数?模板中的函数指针?在下面的代码中。
#include<iostream>
using namespace std;
class A
{
int temp;
public:
A():temp(1){}
template<class T, void (*fn)(T* )>
static void create(T *ptr)
{
cout <<"create fn"<<endl;
//fun1(ptr);
}
static void fun1(A* tp)
{
cout<<"func temp"<<endl;
}
static void fun2(A& ob)
{
cout<<"fun2 start"<<endl;
A::create<A,&A::fun1>(&ob);
cout<<"fun2 end"<<endl;
}
};
int main()
{
A ob,ob1;
ob.fun2(ob1);
}
【问题讨论】:
标签: c++ templates function-pointers static-methods