Why must we specify template arguments for template base class when calling its constructor?

风流意气都作罢 提交于 2020-06-27 09:03:50

问题


The following code snippet compiles only if I explicitly specify the template argument T for the Base struct in Derived ctor:

template <class T>
struct Base
{
    Base(int) {}
};

template <class T>
struct Derived : Base<T>
{
    Derived(int i) : Base<T>(i) {}
};

If I call Base(i) instead of Base<T>(i) - it doesn't work. Why can't compiler determine that Base is actually Base<T> (because I derive from Base<T>)? Is this requirement made intentionally?

来源:https://stackoverflow.com/questions/52632748/why-must-we-specify-template-arguments-for-template-base-class-when-calling-its

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!