I tried to use copy constructor using statement:
X y = X();
But copy constructor is not being called. I am using g++ 4.1.0. I set both X(const X&) and X(x&) constructor in the class.
Is this supposed to work or I am doing some very basic problem in the code?
My code for the class is
class A
{
public:
int i;
A(int ii)
{
i = ii;
}
A(const A&)
{
i = 5;
}
A(A&)
{
i = -1;
}
A()
{
i = 5000;
}
};
When I use it using
A a = A();
or A a = A(100);
, it does not work but when i use it A a(b);
or A a = b;
it works fine.
What is the point I am missing? I saw that according to wikipedia , it should work but it's not working in my case :(.
Thanks in advance for all your answers and comments.