I've been searching the internet and asking my friends for an answer for a good hour to help me with this tiny little error in my code. This is what I try to run:
BinStabloMapa<string,string> m; string s1("Sarajevo"), s2("Zagreb"); m[s1] = "BiH"; m[s2] = "Hrvatska"; { BinStabloMapa<string,string> m2(m); BinStabloMapa<string,string> m3; m3=m; m.obrisi(s1); cout << m2.brojElemenata() << " "; cout << m2[s1] << " "; cout << m3.brojElemenata() << " "; cout << m3[s1] << " "; } cout << m.brojElemenata(); cout << " '" << m[s1] << "' "; m.obrisi(); cout << m.brojElemenata(); cout << " '" << m[s2] << "'"; And this is the error: error: invalid initialization of non-const reference of type 'BinStabloMapa< >&' from a temporary of type 'BinStabloMapa< >* const'|
It shows the error in my operator =:
template <typename TipKljuca,typename TipVrijednosti> BinStabloMapa<TipKljuca,TipVrijednosti>& BinStabloMapa<TipKljuca,TipVrijednosti>::operator =(const BinStabloMapa<TipKljuca,TipVrijednosti> &m) { if(this==&m) return this; // ERROR APPEARS HERE obrisiPomocna(korijen); korijen=0; kopiraj(korijen, m.korijen, 0); return *this; } I'm not quite sure what am I doing wrong here, since I've been taught to make the operator = like this: the protection of self-destrcution + the destructor + the copy constructor. The code that I'm trying to run should be able to compile, since it's the autotest for my whole program. Sorry if I didn't explained it too well, still learning C++ and all the english terms :)
windows? It's often good to provide such information, but I don't see how it applies.