小编Old*_*der的帖子

C++中的继承和模板 - 为什么继承成员不可见?

当模板公开继承自另一个模板时,不是应该可访问的基本公共方法吗?

template <int a>
class Test {
public:
    Test() {}
    int MyMethod1() { return a; }
};

template <int b>
class Another : public Test<b>
{
public:
    Another() {}
    void MyMethod2() {
        MyMethod1();
    }
};

int main()
{
    Another<5> a;
    a.MyMethod1();
    a.MyMethod2();
}
Run Code Online (Sandbox Code Playgroud)

好吧,海湾合作委员会对此嗤之以鼻......我必须遗漏一些完全明显的东西(大脑融化).救命?

c++ inheritance templates

22
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

inheritance ×1

templates ×1