Am a newbie in C++. Can you guys please tell why the copy constructor is being called after the supplied one argument constructor is called?
Expand|Select|Wrap|Line Numbers
- class A
- {
- private:
- int value;
- public:
- A(int val) { value = val; std::cout << "\nOne argument constructor called";}
- A() { value = 0; std::cout << "\n0 argument constructor called";}
- A(A& b) { *this = b; std::cout << "\nCopy constructor called " << this;}
- };
- int main()
- {
- int hi;
- A b = A(2); //why is copy constructor also called after one argument constructor
- std::cin >> hi;
- return 0;
- }