Imagine following scenario
I have a classes A
and B
/* A class with a shared pointer */
class A {
public:
//...
private:
std::shared_ptr<object_t> m_ptr;
};
/* A class with an unique pointer */
class B {
public:
//...
private:
std::unique_ptr<object_t> m_ptr;
};
I want to have a function, which will use the object pointed by m_ptr
and process it, but will not take ownership of it. Should the function take a smart pointer as an argument like
void process(std::shared_ptr<object_t> obj);
or should it use a raw pointer like
void process(object_t* obj);
Edit:
Apparently, I forgot about an important 3rd option for the function
void process(object_t& obj);
which as pointed out by kotatsuyaki should be the preferred solution.