class A {};
class B { public: B (A a) {} };
A a;
B b=a;
I read this from http://www.cplusplus.com/doc/tutorial/typecasting/ . It says this is a implicit type conversion. From class A to class B.
I want to ask, is this also an example of copy constructor?
Thanks.
No, it’s not a copy constructor. A copy constructor copies one object of one type into another of the same type:
As a side note, if you need a copy constructor then you also need a destructor and an assignment operator, and probably a swap function.
What
B::B(A)is is a conversion function. It’s a constructor that allows you to convert an object of typeAinto an object of typeB.