我正在学习 c++ 教程并且很难理解以下代码的一部分(请参阅注释部分):
#include<iostream>
using namespace std;
class A
{
public:
A(A&src)
{
cout<<"copying A..."<<endl;
}
A(void){}
void Do(void)
{
cout<<"A is doing something"<<endl;
}
};
class B
{
public:
B(B&src)
{
cout<<"copying B..."<<endl;
}
B(void){}
void Do(void)
{
cout<<"B is doing something"<<endl;
}
};
class Compo
{
public:
Compo(Compo &src):f1(f1),f2(f2)//???
{
cout<<"Copying Compo..."<<endl;
}
Compo(void){}
A f1;
B f2;
};
int main(void)
{
Compo co1;
Compo co2=co1;
co2.f1.Do();
co2.f2.Do();
}
那么编译器怎么知道哪个f1/f2属于哪个Compo呢?有没有办法让它更明确?
谢谢您的帮助