Error: Invalid initialization of non-const reference of type '.. &' from a temporary of type '...*const'

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 :)

Answers


Change return this to return *this.


Need Your Help

Richfaces modal panel and a4j:keepAlive

jsf richfaces modal-dialog ajax4jsf keep-alive

I've got unexpected problems with richfaces (3.3.2) modal panel. When i try to open it, browser opens two panels instead of one: one is in the center, another is in the upper left corner. Besides, no