这只是一个快速的问题,可以正确理解当您使用如下构造函数创建类时会发生什么:
class A
{
public:
A() {}
};
Run Code Online (Sandbox Code Playgroud)
我知道没有生成默认构造函数,因为它已经定义,但是由编译器生成的复制和赋值构造函数,或者换句话说,我是否需要声明私有复制构造函数和私有赋值运算符以防止这种情况发生?
class A
{
private:
// needed to prevent automatic generation?
A( const A& );
A& operator=( const A& );
public:
A() {}
};
Run Code Online (Sandbox Code Playgroud) c++ copy-constructor default-constructor assignment-operator