c++ - Error while Overloading operator = -


Iv created a red black tree called layerOneTree and now I want the overload operator for it but I do not know the syntax.

  const layerOnline & amp; Operator = (Constant Layer Announcement & PRS); // in layerOneTree.h  

Implementation:

layerOneTree & amp; LayerOneTree :: Operator = (Constant Layer Owner & RA) // Error (if (it! = & Amp; RA) // If Not Self Assignment {Reclaim Memori (M-ROT-> RBILPTR); // Clear Your Memory Do m_root-> rChildPtr = theLeaf; M_root-> gt; rChildPtr = clone (rhs.m_root-> rChildPtr);} return * this; // current tree object return)

I know that there is a problem with layerOneTree * layerOneTree :: operator = , but I do not know how to fix it.

Edit: When I use const layerOneTree & amp; Operator = (Constant Layer Announcement & RA); Everything is fine, but IM is trying to write my code. As you see in line 43, the definition const is why that code works and not mine?

The definition and declaration of member work is to match. Both solutions have to return the same type of variable:

  const layerOneTree & amp; Operator = (Constant Layer Announcement & PRS); // in layerOneTree.h const layerOnline & amp; LayerOneTree :: Operator = (Constant Layer Announcement & PRS) {// code}  

Or:

  layerOneTree & amp; Operator = (Constant Layer Announcement & PRS); // in layerOneTree.h LevelOnatory & amp; LayerOneTree :: operator = (const layerOneTree & amp; rhs) {// code}  

I like the other way because it's easy and easy to understand.

The difference between behavior between the two can be found here:


Comments