我不明白为什么一个具有已删除的复制构造函数的类(或包含成员,如ifstream,具有已删除的复制构造函数,并且它也具有已删除的复制构造函数)的类不能与make_shared()一起使用?这段代码显示了我在说什么
class X {
private:
X(const X&) = delete;
int x;
public:
X(int an_int) : x{an_int} {};
X() : x{10} {}
};
int main(int argc, char** argv)
{
// fails because X has no copy constructor
shared_ptr<X> ptr { make_shared<X>( X{8} ) };
shared_ptr<X> ptr2 { new X{10} };// works fine
return 0;
}
Run Code Online (Sandbox Code Playgroud)