Hello,
I have a question about return types.
So suppose we have a class NameClass that has as private attributes list<thing1> and that i want to create a method that adds to a "new thing" to the list.
so
"return type " NameClass::addThing(const thing1& t).
would it make sense to have the return type as NameClass& and return *this
or should i just have the return type as void?
The drawback is that facilitating chained operations expects a certain level of maturity from the users of the class.
For example, this would engender undefined behaviour prior to C++17:
1 2
int i = 10 ;
std::cout << i << i++ << '\n' ; // chaining is possible because operator<< returns std::ostream&