samedi 23 mai 2020

When this temporary object is destoryed?Before entry the function or after the function returned?

When this temporary object(CTest()) is destoryed?Before entry the function(fooFunc) or after the function(fooFunc) returned?

I know the code below is not right indeed(Thank you,asmmo. ). The reason is that:

"The idea is that a function taking a non-const reference parameter is stating that it wants to modify the parameter and allowing it to go back to the caller. Doing so with a temporary is meaningless and most likely an error."

I would be thankful for any hint about this question.

class CTest;
void fooFunc(CTest&){};
fooFunc(CTest());

Aucun commentaire:

Enregistrer un commentaire