I do this, because this function, SetOwnedPointer, should never change the LorentzM* momentum_In nor should it change the object that it points to, so constant pointer to constant object it is.
That's not reason enough. The function may not change the object directly, but it is granting another object (the shared_ptr
) rights to modify the object. It can't grant rights that it doesn't have itself. So change it to a pointer to a non-const object.
It's the same thing, for example, if you have a class that has a non-const reference member. You need to pass a non-const object to its constructor, even if the constructor does not itself modify the object. The constructor needs to grant the object's reference member rights to modify the object, and it can't do that if it does not itself have those rights.