//定義了一個類,定義三個函式,見下面:
class CTestF
{
protected:
bool F1(int a, int b);
bool Test(int m, int n, bool (*pf)(int ,int));
void Get();
};
bool CTestF::F1(int a, int b)
{
if(a>b) return true;
else return false;
}
bool CTestF::Test(int m, int n, bool (*pf)(int ,int))
{
return pf(m,n);
}
void CTestF::Get()
{
int t = 10;
int h = 20;
Test(t, h, F1);//此處提示F1錯誤:bool (TestF::*)(int a, int b)" 型別的實參與 "bool (*)(int, int)" 型別的形參不兼容
//錯誤 C3867 “TestF::F1”: 非標準語法;請使用 "&" 來創建指向成員的指標
// 而用&F1也提示錯誤!
}
----------在線急等大俠指教!!!!!!!
uj5u.com熱心網友回復:
// 如果不定義類中,則沒有問題int T1(int a, int b)
{
return a+b;
}
int TF(int m, int n, int (*pT)(int,int))
{
return pT(m,n);
}
int GT()
{
return TF(10,20,T1);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/266828.html
標籤:基礎類
