#include <iostream>
#include <string>
using namespace std;
class interface
{
public:
bool say()
{
printf("interface ok\n");
return true;
}
};
template<typename gf>
class grandfather
{
private:
string mgf;
public:
grandfather(string igf)
{
mgf = igf;
}
template<typename TResult>
TResult CallFunction(TResult& func(gf))
{
gf cgf;
TResult result;
result = func(cgf);
return result;
}
};
template<typename f>
class father :public grandfather<f>
{
private:
string mf;
protected:
father():grandfather<f>(mf)//顺便调用基类的有参构造
{}
public:
bool Fun_father_text(f cfa)
{
retrun cfa.father_text();
}
template<typename TResult>
bool father_text()
{
bool result;
result = this->CallFunction<bool>(Fun_father_text);
}
};
class son :public father<interface>
{
bool father<interface>::father_text();//结合这个
};
int main()
{
son son1;
if (son1.father_text())//应该怎么改才能让这个不报错
{
cout << "ture" << endl;
}
else
{
cout << "fase" << endl;
}
return 0;
}
上面这个是程序,就只需要不报错就行了,我改了son的声明方式,或者虚函数都没有不报错。其实就是想纠正一些我的知识错误。感谢