I’ve got kind of an issue here with c++ – I’ve got two classes:
class vec and class vecD : public vec
class vec overloads pretty much any operator – some of them (as +=) return an object of the class itself for obvious reasons. Now my questions is: is it possible to reuse the overloaded functions of vec for vecD but return a vecD object instead? I mean for sure it’s possible to define all functions virtual and redefine them all over again…but, you know there must be some smoother way?
EDIT: Sorry, sure some code: Is it possible to use inheritance like that? Starting from a templated class? Can I reuse them operators from the parents class?
template<typename TYPE>
class vec{
public:
TYPE *val;
int dimension;
public:
vec();
~vec();
TYPE operator[](int right);
virtual vec<TYPE>& operator=( TYPE right );
virtual vec<TYPE>& operator=( vec<TYPE> right );
virtual vec<TYPE> operator+( TYPE right );
virtual vec<TYPE> operator-( TYPE right );
[etc]
};
class vecD : public vec<long>{
public:
long *X;
long *Y;
long *Z;
long *Xmax;
long *Ymax;
long *Zmax;
public:
vecD();
~vecD();
long getAddress();
long setAddress( long _X, long _Y, long _Z );
TYPE operator[](int right);
virtual vecD<long>& operator=( long right );
virtual vecD<long>& operator=( vecD<long> right );
virtual vecD<long>& operator=( vec<long> right );
virtual vecD<long> operator+=( vecD<long> right );
[etc]
};
Judging by the comments, this might also interest you: