c++ - QVector<T> operator= and operator[] -


i'm writing program friends during summer time , occurred strange problem.

i'm assigning qvector< t > other qvector< t > operator= in homemade template class , trying check whethere 2nd qvector< t > have elements. first, i'm checking it's size , it's good, when use operator[] , function getname() member of class t.

here's code:

 template <template t> class turniej {  private:   qvector<t>* list_;   qvector<stol<t> > stoly_;   int round_;   int max_rounds_;   turniej() {round_=1;}  public:   static turniej& getturniej() {    static turniej turniej;    return turniej; }   void setlist(qvector<t> *list) {list_=list; }   qvector<t>& getlist() {return *list_;}   //some other irrelevant methods  }; 

then invoke setlist() function reference qvector filled 2 objects of gracz class

  turniej<gracz>::getturniej().setlist(&list) 

and when i'm trying list_ object in turniej class code below, error: assert failure in qvector::operator[]: "index out of range", file .../qtcore/qvector.h, line 356

 qdebug()<<turniej<gracz>::getturniej().getlist()[0].getname(); 

where getname() returns qstring , method exists in gracz class.

i appreciate help, because i'm stuck 2 days , have no idea what's going on. strange, trying google error haven't found topic error in particular line of qvector.h. i'm using qt 5.0.2 qt creator

thanks help!

when call setlist, transferring ownership of list, shure not deleting (or not getting deleted automatically) afterwards?


Comments