This is mostly a syntax question. Here's a related thread showing different alternatives to achieve the same result: Method-Chaining in C#
Now, in C++ it is possible to chain commands on an object by making methods return the pointer to the object of which the method is a member.
The syntax I'm looking for is:
foo.Transform(bar).TransformDifferently(yay);
In C#, if I return this, the value is copied (edit: half incorrect, read answers). I don't think I can return a reference or a pointer, can I? Is there any other way to achieve the same syntax?
For now my solution is to just assign the result to my object, like so:
foo = foo.Transform(bar).TransformDifferently(yay);
It's however not the optimal solution, because it's both slower (doesn't matter in my case) and more verbose. I'd be very happy for any pointers in the right direction!