相关疑难解决方法(0)

C++继承的模板类无权访问基类

我是第一次使用模板类,并试图找出编译器在使用inheritence时似乎不喜欢的原因.

这是代码:

template <typename T>
struct xPoint2
{
    T x;
    T y;

    xPoint2() { x = 0; y = 0; };
};

template <typename T>
struct xVector2 : xPoint2<T>
{
    xVector2() { x = 0; y = 0; };
};
Run Code Online (Sandbox Code Playgroud)

编译器输出:

vector2.hh: In constructor ‘xVector2<T>::xVector2()’:
vector2.hh:11: error: ‘x’ was not declared in this scope
vector2.hh:11: error: ‘y’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

是不是可以这样使用模板?

谢谢

c++ inheritance templates

1
推荐指数
1
解决办法
1991
查看次数

标签 统计

c++ ×1

inheritance ×1

templates ×1