I'm trying to use smart pointers in my class, but, I don't know why, I can't make it work. Here is a simplified version of my class:
class Project {
public:
std::shared_ptr<Part> getPart() const {
return m_part;
}
void setPart(const Part &part) {
m_part = std::make_shared<Part>(part);
}
private:
std::shared_ptr<Part> m_part;
};
The problem is if I pass a Part
object (let's call it some_part
) to the setPart()
method and after making changes to some_part
, the property m_part
is unchanged, like if it points to a copy rather than to some_part
itself. Why am I seeing this behaviour?