0
我有两个具有许多函数的类(函数不能是'静态')。 我想通过模板函数每次调用另一个函数。 我试图编写模板函数,但我不知道如何使用我想要的类函数调用模板函数。 我附加了一个简单的代码的问题:通过模板函数调用类函数
class FirstClass
{
public:
FirstClass()
{
int y = 7;
y++;
}
void FirstFunction(int x)
{
x++;
}
};
class SecondClass
{
public:
SecondClass()
{
int y = 7;
y++;
}
void SecondFunction(int y)
{
y--;
}
void ThirdFunction(int y)
{
y--;
}
};
template<class OBJECT, void (*FUNCTION)>
void Test(int x)
{
OBJECT *a = new OBJECT();
a->FUNCTION();
delete a;
}
void main()
{
Test<FirstClass, &FirstClass.FirstFunction>(5);
Test<SecondClass, &SecondClass.SecondFunction>(5);
Test<SecondClass, &SecondClass.ThirdFunction>(5);
}
谢谢...
您的意思是x'传递参数'的成员函数调用时?你的代码只有'FUNCTION()' – Brian