My base class:
class Element
{
public:
Element();
virtual ~Element(){};
virtual Element& plus(const Element&);
virtual Element& minus(const Element&);
};
Derived Template Class:
#include "Element.h"
template <class T>
class Vector: public Element {
T x, y, z;
public:
Vector();
Vector(const T& x, const T& y = 0, const T& z =0);
Vector(const Vector& u);
...
Element& plus(const Element&) const;
Element& minus(const Element&) const;
...
};
...
template <class T>
Element& Vector<T>::plus(const Element& v) const
{
const Vector<T>& w = static_cast<const Vector<T>&>(v);
Vector<T>* ret = new Vector<T>((x + w.x), (y + w.y), (z + w.z));
return *ret;
}
template <class T>
Element& Vector<T>::minus(const Element& v) const
{
const Vector<T>& w = static_cast<const Vector<T>&>(v);
Vector<T>* ret = new Vector<T>((x - w.x), (y - w.y), (z - w.z));
return *ret;
}
I had another problem with this code (answered in another post ), but I'm currently struggling with that if I try to run this, I get
Undefined : ":: ( const amp;)", :
vtable Vectorin main.o
":: ()", :
:: () main.o
Vector:: Vector (double const &, double const &, double const &) main.o
:: ( const &) ", :
vtable Vectorin main.o
" typeinfo Element", :
typeinfo Vectorin main.o
ld:
collect2: ld 1
, , , ( , )?
++ , vtables , .