下列程序定义,请选择类 A 的拷贝构造函数被执行的次数()
#include <iostream>
#include <cmath>
using namespace std;
class A
{
public:
A(int xx=0)
{
X=xx;
}
A(A&p);
int GetX()
{
return X;
}
private:
int X;
};
A::A(A&p)
{
X=p.X;
}
class B
{
public:
B(A x1,A x2);
B(B &);
double GetLen()
{
return len;
}
private:
A p1,p2;
double len;
};
B::B(A x1,A x2):p1(x1),p2(x2)
{
len=2*double(p1.GetX()-p2.GetX());
}
B::B(B&S)
{
p1=S.p1;
p2=S.p2;
len=S.len;
}
int main()
{
A m1(1),m2(2);
B m3(m1,m2);
B m4(m3);
count<<m3.GetLen()<<endl;
count<<m4.GetLen()<<endl;
return 0;
}