W
weinma81
Hi!
I'm writing a vector-class for some calculations and it look's like i
am having a covariant problem, where i shouldn't:
The Vector-Class Look's like this and works:
template <int _size,class T>
class Vector {
protected:
T vector[_size];
public:
...
virtual Vector<_size,T> operator-(const Vector<_size,T> &v)
const; // that's one of the methods causing problems
As the crossproduct is only defined for a 3D Vector i wanted to write
and inherit a Vector3 from Vector.
The operators should also return the Vector3 so i overwrote them.. and
there comes my covariant problem.
Looks like this:
template <class T>
class Vector3 : public Vector<3,T> {
public:
...
Vector3<T> operator-(const Vector<3,T> &v) const; // <-- Theres my
problem
Compiler cries:
.../Vector3.h:56: error: invalid covariant return type for 'Vector3<T>
Vector3<T>:
perator-(const Vector<3, T>&) const [with T = float]'
.../Vector.h:72: error: overriding 'Vector<_size, T> Vector<_size,
T>:
perator-(const Vector<_size, T>&) const [with int _size = 3, T =
float]'
don't know what to do.. asked some people but they also said that this
should work..
regards
Weinma
I'm writing a vector-class for some calculations and it look's like i
am having a covariant problem, where i shouldn't:
The Vector-Class Look's like this and works:
template <int _size,class T>
class Vector {
protected:
T vector[_size];
public:
...
virtual Vector<_size,T> operator-(const Vector<_size,T> &v)
const; // that's one of the methods causing problems
As the crossproduct is only defined for a 3D Vector i wanted to write
and inherit a Vector3 from Vector.
The operators should also return the Vector3 so i overwrote them.. and
there comes my covariant problem.
Looks like this:
template <class T>
class Vector3 : public Vector<3,T> {
public:
...
Vector3<T> operator-(const Vector<3,T> &v) const; // <-- Theres my
problem
Compiler cries:
.../Vector3.h:56: error: invalid covariant return type for 'Vector3<T>
Vector3<T>:
.../Vector.h:72: error: overriding 'Vector<_size, T> Vector<_size,
T>:
float]'
don't know what to do.. asked some people but they also said that this
should work..
regards
Weinma