+ 1
How to ensure no access after std::move
Hi Refer code below: As we moved, we should not access object t1... As we accessed it post moving, it throws error. it is easy to remember in small size of code that object is moved, but is there any mechanism to avoid such problems? https://code.sololearn.com/c3Vs4rhwjyDL/?ref=app
2 Respostas
0
I don't know the best practice in this case, but maybe you could treat t1 like a freed object and get in the habit of always setting it to nullptr after you are done with it.
0
Thanks Brian but t1 is not pointer to object. It is object which is moved and hence can't check with null pointer