if you have a clear() function that clears all elements in an array, do you use the void type or the referens to the type you are working with and returning *this.
Ex.
void Vector<T>::clear() {
}
or
Vector& Vector<T>::clear(){
return *this
}
I don’t really understand when to return “this” and when to use void type.
I assume returning
*thisis useful to chain API calls.obj.doSomething().doSomethingElseAfterwards(). So calls where chaining is useful, such asaddare good candidates for*this. And methods where chaining is not very useful might returnvoid.Personally I’m not fond of this chaining style, but many people like the fluent APIs this allows.