Hi All,
I am a newbie and I need help with this (urgently if possible).
I am deriving a template class from QVector in order to add more functionality to be able to convert the types store in the QVector and also carry out math operations like multiplications.
#ifndef MVECTOR_H
#define MVECTOR_H
#include <QVector>
#include <typeinfo>
#include <QString>
template <typename T>
class mVector:public QVector<T>
{
bool numeric;
public:
mVector<T>():QVector<T>(){numeric=false;} //the vector contains non-numeric by default.
mVector<T> operator*(mVector<T> a);
bool isNumeric();
mVector<float> toNumeric();
mVector<QString> toString();
mVector<T> operator=(mVector<T>);
};
#endif //
#include "mvector.h"
template <typename T>
mVector<T> mVector<T>::operator*(mVector<T> a){
mVector<T> c;
if(this->size()==a.size())
{
for(int i=0;i<a.size();i++)
c[i]=this->at(i)*a[i];
}
return c;
}
template <typename T>
bool mVector<T>::isNumeric(){
return numeric;
}
template <typename T>
mVector<float> mVector<T>::toNumeric(){
mVector<float> tm;
if(!numeric){
for(int i=0;i<this->size();i++)
tm.append(float(this->at(i)));
//this=&tm;
}
tm.numeric=true;
return tm;
}
template <typename T>
mVector<QString> mVector<T>::toString(){
mVector<QString> strv;
if(numeric){
for(int i=0;i<this->size();i++)
{
strv.
append(QString::number(this
->at
(i
)));
}
}
strv.numeric=false;
return strv;
}
template <typename T>
mVector<T> mVector<T>::operator=(mVector<T> a){
this->resize(a.size());
for(int i=0;i<this->size();i++)
*this[i]=a[i];
return *this;
}
#ifndef MVECTOR_H
#define MVECTOR_H
#include <QVector>
#include <typeinfo>
#include <QString>
template <typename T>
class mVector:public QVector<T>
{
bool numeric;
public:
mVector<T>():QVector<T>(){numeric=false;} //the vector contains non-numeric by default.
mVector<T> operator*(mVector<T> a);
bool isNumeric();
mVector<float> toNumeric();
mVector<QString> toString();
mVector<T> operator=(mVector<T>);
};
#endif //
#include "mvector.h"
template <typename T>
mVector<T> mVector<T>::operator*(mVector<T> a){
mVector<T> c;
if(this->size()==a.size())
{
for(int i=0;i<a.size();i++)
c[i]=this->at(i)*a[i];
}
return c;
}
template <typename T>
bool mVector<T>::isNumeric(){
return numeric;
}
template <typename T>
mVector<float> mVector<T>::toNumeric(){
mVector<float> tm;
if(!numeric){
for(int i=0;i<this->size();i++)
tm.append(float(this->at(i)));
//this=&tm;
}
tm.numeric=true;
return tm;
}
template <typename T>
mVector<QString> mVector<T>::toString(){
mVector<QString> strv;
if(numeric){
for(int i=0;i<this->size();i++)
{
strv.append(QString::number(this->at(i)));
}
}
strv.numeric=false;
return strv;
}
template <typename T>
mVector<T> mVector<T>::operator=(mVector<T> a){
this->resize(a.size());
for(int i=0;i<this->size();i++)
*this[i]=a[i];
return *this;
}
To copy to clipboard, switch view to plain text mode
creating an instance and calling any of its functions
mVector<QString> s;
mVector<float> n;
s.append("3.445");
n=s.toNumeric();
mVector<QString> s;
mVector<float> n;
s.append("3.445");
n=s.toNumeric();
To copy to clipboard, switch view to plain text mode
gives this error. i included all dependencies to no avail.
./debug\mainwindow.o:L:\Qt Codes\LoadCombination\LoadCombination-build-desktop/../LoadCombination/mainwindow.cpp:156: undefined reference to `mVector<float>::operator=(mVector<float>)'
Thanks in advance for your intervention and help.
Bookmarks