I have a variable a whose type is A.
A a;
I want to call a function which takes a const reference of type A as an input argument.
fun(const A &a);
After some code changes I decided it is best to change the type of variable a to std::shared_ptr<A>
std::shared_ptr<A> a;
What is the best way to change function fun so that I make sure that object a is never changed (it should remain const)?
should fun remain as it is and I should call it like:
fun(*a.get())
or is there any alternative? Somehow this feels ugly to me...
I guess simply changing fun to fun(const std::shared_ptr<A> &a) will not work because I want to make sure that the function does not change the underlying object and not the shared pointer.
I cannot use std::shared_ptr<const A> a because it is necessary to change variable a at some point.