+ 1

How to ensure function does not modify shared pointer

How to avoid function modifying shared or unique pointer modified by using ptr.reset

14th Jul 2025, 11:44 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
5 Antworten
0
Idk like be sure or somethn
14th Jul 2025, 2:04 PM
LardMan
LardMan - avatar
0
check if pointer is null?
14th Jul 2025, 2:25 PM
Bob_Li
Bob_Li - avatar
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.
14th Jul 2025, 3:20 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
wouldn't it make sense to first do a null check? https://sololearn.com/compiler-playground/caC7H08qS4fy/?ref=app
14th Jul 2025, 3:39 PM
Bob_Li
Bob_Li - avatar
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.
14th Jul 2025, 3:42 PM
Ketan Lalcheta
Ketan Lalcheta - avatar