我四处寻找解决我的问题的方法,发现了很多关于循环引用和命名空间问题(都不适用于我的情况),但没有像我遇到的问题那样。
我在 maths/matrix.h 中定义并实现了一个模板类:
template<class T>
class Matrix
{
public:
// constructors, destructors and what not...
};
我在 maths/vector.h 中定义并实现了另一个模板类
#include <maths/matrix.h>
template<class T>
class Vector : public Matrix
{
public:
// constructors, destructors and what not...
};
我在 vector.h 中收到此错误“expected class-name before '{' token”真烦我。这与matrix.h和vector.h位于数学子文件夹中没有任何关系,因为我可以在应用程序的其他部分使用matrix.h,没有任何问题。我认为这与 Matrix 作为模板类有关,因为当我将 Vector 设为非模板类的子类(例如 SomeClass.h)时,一切都可以正常编译。
非常感谢任何可以提供帮助的人:)
I've looked around for a solution to my problem and found lots about cyclic references and namespace issues (neither apply in my case), but nothing like the problem I'm having.
I have a template class defined and implemented in maths/matrix.h:
template<class T>
class Matrix
{
public:
// constructors, destructors and what not...
};
I have another template class defined and implemented in maths/vector.h
#include <maths/matrix.h>
template<class T>
class Vector : public Matrix
{
public:
// constructors, destructors and what not...
};
I get this error "expected class-name before ‘{’ token" in vector.h which is really bugging me. It's not anything to do with matrix.h and vector.h being in a maths sub-folder because I can use matrix.h in other parts of my application without any problems. I think it has something to do with Matrix being a templated class because when I make Vector a subclass of a non-templated class (SomeClass.h for example) everything compiles ok.
Many thanks to anyone that can help :)
发布评论
评论(2)
您需要从具体类继承,即从 Matrix 继承,而不仅仅是 Matrix:
You need to inherit from the concrete class, i.e. from
Matrix<T>
, not merelyMatrix
:你错过了两件事。
You're missing two things.