c++ - Template Class Assignment Operator Overloading -


i'm having little trouble following:

i'm writing map abstract data type coursework & i've come across problem whilst trying assign object of class (mapentry - below) array of same type in class mapadt. tells me that:

error 1 error c2679: binary '=' : no operator found takes right-hand operand of type 'mapentry *' (or there no acceptable conversion) c:\users\cross_000\documents\visual studio 2013\projects\objectorientedmethodsasignment1\mapadt\mapadt.h 14

so thought write own assignment operator override. i've done in mapentry class definition compiler doesn't seem recognize when try initialize array in constructor on mapadt - below.

any appreciated.

#pragma once  template <class tk, class tc> class mapentry { private:     tk key;     tc contents;     bool ispopulated;  public:     mapentry() {      }      mapentry(tk keyinput, tc contentsinput) {         key = keyinput;         contents = contentsinput;         ispopulated = true;     }      mapentry(tk keyinput, tc contentsinput, bool ispopulatedinput) {         key = keyinput;         contents = contentsinput;         ispopulated = ispopulatedinput;     }      ~mapentry() {         //todo     }      tk getkey() {         return key;     }      void setkey(tk keyinput) {         key = keyinput;     }      tc getcontents() {         return contents;     }      void setcontents(tc contentsinput) {         contents = contentsinput;     }      bool getispopulated() {         return ispopulated;     }      void setispopulated(bool ispopulatedinput) {         ispopulated = ispopulatedinput;     }      mapentry<tk, tc>& operator=(const mapentry<tk, tc> & lst)     {         clear();         copy(lst);         return *this;     } }; 

mapadt.h

#pragma once #include "mapentry.h"  template <class tk, class tc> class mapadt { private:     int mapsize = 1000;     mapentry<tk, tc> *map; public:     mapadt() {         map = new mapentry<tk, tc>[mapsize];         (int = 0; < mapsize; i++) {             map[i] = new mapentry<tk, tc>(null, null, false);         }     } } 

there's more mapadt class don't think it's relevant. if need see whole thing can add it.

map[i] not pointer mapentry.

not sure if want

map[i] = mapentry<tk, tc>(null, null, false); 

or

mapentry<tk, tc>** map;  mapadt() {     map = new mapentry<tk, tc>*[mapsize];     (int = 0; < mapsize; i++) {         map[i] = new mapentry<tk, tc>(null, null, false);     } } 

to solve issue.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -