Assume I have a class, which contains a smart pointer as its member variable:
class B;
class A {
public:
A(const std::shared_ptr<B>& b) : b_(b) {} // option1: passing by reference
A(std::shared_ptr<B> b) : b_(b) {} // option2: passing by value
std::shared_ptr<B> b_;
};
I have two choices for A's constructor: construct by smart pointer and construct by smart pointer's reference.
What are the advantages and disadvantages of these two methods?
Is copying the smart pointer wasteful?