I would like to overload << operator for chaining like below
function1(param1, param2)<< obj2 << obj3 << string4
function1 would return an object.
What I want to do is after string4, I need to call a function using param1, param2.
My questions will be
-
How do I know string4 is the last parameters in the expression and hence I need to call another function2 using param1 and param2 or it isn’t possible to do so?
-
How do I pass param1 and param2 to the function to be called? I could not store the param1 and param2 in the object as it is a multithreaded.
Thanks.
You can return a helper object from
function1by value which callsfunction2in it’s destructor.Consider this example:
This program prints
The idea is that at the end of your line, the
Function2Callerobject goes out of scope and the destructor then does its work.Please note that when implementing this you should probably forbid copying of Function2Caller objects and make
function1the only one who can call theFunction2Callerconstructor.