class A
{
private:
int value;
public:
A(int n)
{
value = n;
}
A(const A &other)//注意剑指offer里面此处把拷贝构造函数形参变为引用类型还是出错,必须是常量引用才行
{
cout<<"拷贝构造";
value = other.value;
}
/* A& operator= (const A & other)
{
cout<<"赋值操作符";
value = other.value;
return *this;
}*/
void Print()
{
cout<< value;
}
};
int main()
{
A a = 10;//注意剑指offer里面此处把拷贝构造函数形参变为引用类型还是出错,必须是常量引用才行
A b = a;
b.Print();
return 0;
}
{
private:
int value;
public:
A(int n)
{
value = n;
}
A(const A &other)//注意剑指offer里面此处把拷贝构造函数形参变为引用类型还是出错,必须是常量引用才行
{
cout<<"拷贝构造";
value = other.value;
}
/* A& operator= (const A & other)
{
cout<<"赋值操作符";
value = other.value;
return *this;
}*/
void Print()
{
cout<< value;
}
};
int main()
{
A a = 10;//注意剑指offer里面此处把拷贝构造函数形参变为引用类型还是出错,必须是常量引用才行
A b = a;
b.Print();
return 0;
}