c++ - error: undefined reference to `vector<int>::pushBack(int const&)' -


i create vector class , in qt wrote code

this click action trying add new value in vector click action

void mainwindow::manuelclick()  {      int b=0;      vector<int> a;      a.pushback(10);      for(int i=0;i<a.size();i++)      {          b=a.getarray(i);          qstring str=qstring::number(b);          ui->mbox->settext(str);      } 

these errors got

undefined referance vector<int>::pushback(int const&) undefined referance vector<int>::size() undefined referance vector<int>::vector() undefined referance vector<int>::getarray(int) undefined referance vector<int>::~vector() undefined referance vector<int>::~vector() collect2: error: ld returned 1 exit status 

when delete code there no error

here "vector.h"

 #include<iostream>     template <class t>     class vector     {         int vsize,maxsize;         t* array;         void alloc_new();     public:         vector();         vector(int);         ~vector();         void pushback(const t&);         void show();         int size();         t operator[](int);         t getarray(int);          vector<t>& operator +=(const vector <t>&);          template<class te>         friend std::ostream& operator<<(std::ostream&,const vector<te> &);          template<class te>         friend std::istream& operator>>(std::istream&,vector<te> & );     }; 

what should help

when writing templates, should define methods right declaration i.e. in header, not cpp file. also, recommend using standard container classes, qvector or std::vector.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -