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 :)
You need to inherit from the concrete class, i.e. from Matrix<T>
, not merely Matrix
:
template<class T>
class Vector : public Matrix<T>
{
…
};
You're missing two things.
template<typename T>
class Vector : public Matrix <T> //<----- first : provide the type argument
{
}; //<-------- second : semi-colon (same from Matrix class also)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With