关于模板类继承,这个程序该怎么改不报错?



#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的声明方式,或者虚函数都没有不报错。其实就是想纠正一些我的知识错误。感谢

建议买本C++Prime学习好语法,再写代码,下面这写的啥玩意

class son :public father<interface>
{
    bool father<interface>::father_text();//结合这个
};
可以看下 c参考手册中的 c语言--存储类指定符

用模板最好系统的学习一下,father_text是一个模板类的模板函数,所以必须要结合具体的模板参数残能确定,而不能直接使用这个函数。