+ 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

27th Feb 2022, 2:59 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 ответов
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.
27th Feb 2022, 4:52 PM
Brian
Brian - avatar
0
Thanks Brian but t1 is not pointer to object. It is object which is moved and hence can't check with null pointer
1st Mar 2022, 4:01 AM
Ketan Lalcheta
Ketan Lalcheta - avatar