I was writing a simple program to show different types of constructors available in C++(default, parametrized, and copy). When I encountered this problem(if that's right to say it a problem). What I'm posting here isn't the actual program but it is a part of the main program.
Code:
#include <iostream>
using namespace std;
class A
{
public:
A (A&)
{
cout << "copy ctor of A.\n";
}
~A ()
{
cout << "dtor of A\n";
}
};
int main()
{
A obj(obj);
return 0;
}
So my question here is:
- What means
A obj(obj);
here? - How copy constructor is taking reference to an object which even doesn't exist in the memory?