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