Acorbe Acorbe - 1 year ago 85
C++ Question

force returned object to be assigned

is there a way, in C++, to force the assignation of the returned value of a function?
i.e. if I have a member function foo

class myClass{
T1 foo(T2 x){T1 y; /*something*/ return y;};

which I can call in the main() as

myClass obj;
T1 a =; //<--

can I make the simpler call

myClass obj;; //<--

(that does not store the returned value) somehow "illegal"?

Alternatively, can I distinguish the definitions of

T1 a =;;

thank you for your time and sorry for my ignorance

Answer Source

No, there's no way to force an operation on a returned object.

And no, you can't distinguish between

T1 a =;;

inside the calls (at least not in a portable, standard way. You could hack away with call-stacks and such, but why would you).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download