【问题标题】:Calling a templated base class method compile fails调用模板化基类方法编译失败
【发布时间】:2016-04-08 20:33:30
【问题描述】:

我正在尝试通过派生类调用模板化基类方法。 这是我的代码

struct base
{
    template<typename t>
    void baseMethod(t s)
    {
        std::cout << s;
    }
};


struct der : public base
{
};


int main()
{
  der d;
  d.<int>(baseMethod(12));
}

编译失败并声明

main.cpp:在函数“int main()”中:main.cpp:25:5:错误:预期 '

关于如何修复它的任何建议?

【问题讨论】:

    标签: c++ templates


    【解决方案1】:

    尽管这个问题与继承无关,但正确的语法应该是

    d.baseMethod<int>(12);
    

    但是,由于template deduction,即使这样也不需要:简单

    d.baseMethod(12);
    

    会起作用的。

    【讨论】:

    • 谢谢。语法让我想起 - 标记为计时器后的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 2018-06-10
    相关资源
    最近更新 更多