Home

On 10 5 , 12 19 , linq936 <linq...@gmail.com> wrote:
> 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::operator=(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?

try
int main()
{
test d;
test b;
b=d;
getchar();
return 0;
}

"test b=d;" will call the copy constructor.

previous
next

Re: public headers
Re: How to insert in a string @ a index
Re: Text processing and file creation
Re: how to get output.
Local Functions...
Dzieci Niczyje
Podaruj Zycie
Fundacja Iskierka
Fundacja Hobbit
Fundacja Avalon