更新时间:2018-11-22 15:41作者:才子老师
};
int main()
{
A a(1,2,3);
}
第 1 种写法是错误的,第 2 种正确。
4.考察拷贝构造函数和赋值的区别。
class A
{
public:
A() { cout<<"Construct A by default"<
A(const A& a) { cout<<"consttuct A by copy"<
A& operator =(const A& a) { cout<<"cosnt A by operator ="<
~A() { cout<<"Destruct A"<
};
int main()
{
A a;
A b=a; //调用拷贝构造函数
A c(a); //调用拷贝构造
A d;
d=a; //赋值
}
输出:
Construct A by default //构造对象 a
consttuct A by copy //拷贝构造 b
consttuct A by copy //拷贝构造 c
Construct A by default //构造 a
cosnt A by operator = //赋值 d=a
Destruct A
Destruct A
Destruct A
Destruct A
5.考察函数指针
voidfunc(char* a)
{
cout<
}
int main()
{