Sha*_*ley 1 c++ inheritance templates
我是第一次使用模板类,并试图找出编译器在使用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)
是不是可以这样使用模板?
谢谢
| 归档时间: |
|
| 查看次数: |
1991 次 |
| 最近记录: |