My class has the following structure:
class S {
public:
S() {}
};
class T {
private:
std::unique_ptr<S> a;
T(S);
public:
static std::unique_ptr<T> make_item() {
std::unique_ptr<S> s_instance = std::make_unique<S>();
return std::make_unique<T>(std::move(s_instance));
}
};
However, when I try to make a unique_ptr in the make_item, it sees the constructor as private.
Is there a way to allow the use of the private constructor in a static member function of the class itself? Because one member is a unique_ptr to S (a rather heavy object), we wish not to use a copy.