While copying the objects if we say X a=b, X a(b) What will it call, assignment operator or copy constructor? Justify

Showing Answers 1 - 10 of 10 Answers

TalasilaNaveen

  • Aug 11th, 2007
 

This calls Copy constructor which assigns/copies the data associated with the object b.

  Was this answer useful?  Yes

Raj

  • Sep 15th, 2007
 


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;


}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions