+ 1
How to ensure function does not modify shared pointer
How to avoid function modifying shared or unique pointer modified by using ptr.reset
5 Antworten
0
Idk like be sure or somethn
0
check if pointer is null?
0
My bad. It works well and can discard this question.
https://sololearn.com/compiler-playground/cepsd2zZkYG5/?ref=app
I wanted to restrict last line of function and can do so by keeping const shared pointer ref as function argument.
0
wouldn't it make sense to first do a null check?
https://sololearn.com/compiler-playground/caC7H08qS4fy/?ref=app
0
My question might not be drafted correctly or precisely.
It's not I want to reset. I want that function should not change ptr. It can change if we use reset.
Reset will throw error when function takes const ref . This is what I wanted.