I have an assignment to overload operator += so it adds new data to the list. List += data should therefore mean list=list+data, which is logically similar to what operator += does with basic types like int etc. I suck at linked lists, I've just figured out how to do it with functions, so I have no idea what to do in this case.
List& List::operator+=(const T& newData)
{
last_ = (!first_ ? first_ : last_->next_) = new Elem(newData);
++listSize_;
return *this;
};
where T is from template <typenameT> class List {...} "
Is this okay, I mean can I use code from function
List& addToList (const T& newData) {same code snippet}
, will it give me expected results? I don't think so, because it never uses operator itself in the code and that kinda confuses me.
As it's obvious I'm a beginner in coding, sorry for my bad cpp :)