L
linq936
Hi,
I have the following code:
#include <iostream>
using namespace std;
class test
{
public:
int x,y;
test ();
test(const test&);
test operator=(const test&);
virtual ~test();
};
test::test(const test& b)
{
cout << "i am in a copy constructor"<<endl;
}
test::~test()
{
}
test::test()
{
}
test test:perator=(const test& b)
{
if (this == &b)
return *this;
cout << "i am using assignment operator "<<endl;
x = b.x;
y = b.y;
return *this;
}
int main()
{
test d;
test b = d;
test e(b);
getchar();
return 0;
}
When I run it I see
i am in a copy constructor
i am in a copy constructor
So that means that the overloaded equal operator function is not
called.
Why is that? Is this compiler dependent? I am using g++. Is there
any document to describe the underline mechanic?
I have the following code:
#include <iostream>
using namespace std;
class test
{
public:
int x,y;
test ();
test(const test&);
test operator=(const test&);
virtual ~test();
};
test::test(const test& b)
{
cout << "i am in a copy constructor"<<endl;
}
test::~test()
{
}
test::test()
{
}
test test:perator=(const test& b)
{
if (this == &b)
return *this;
cout << "i am using assignment operator "<<endl;
x = b.x;
y = b.y;
return *this;
}
int main()
{
test d;
test b = d;
test e(b);
getchar();
return 0;
}
When I run it I see
i am in a copy constructor
i am in a copy constructor
So that means that the overloaded equal operator function is not
called.
Why is that? Is this compiler dependent? I am using g++. Is there
any document to describe the underline mechanic?