class A1{
public:
A1(){}
A1(const A1& rhs){}
void foo() {std::cout<<"Hello";}
};
class A2: public A1{
public:
A2(){}
A2(const A2& rhs){}
void foo1(A1&rhs){rhs.foo();}
void foo2(A1 a1){a1.foo();}
};
int main()
{
A2 a2;
A1 a1(a2);
a2.foo1(a1);
a2.foo2(a1);
}
How many times are the A1's copy constructor invoked? How many times are the A2's copy constructor invoked?
Could anybody can teach me this? thanks!
cout << "in A1's ctor" << endl;in the constructors and run the code to see for yourself.static int i = 0; std::cout << ++i << "th time in A1" << std::endl;