what is difference between copy constructor and assignment operator
-
what is the difference between assignment operator and copy constructor thanx
-
what is the difference between assignment operator and copy constructor thanx
class A { public: A() {} A(const A& t) { std::cout << "Copy ctor\n"; /* ... */ } operator = (A& r) { std::cout << "Assignment ctor\n"; /* ... */ } }; void f() { A aa; A bb = aa; // Copy ctor is used. A cc; cc = aa; // Assignment ctor is used. } Maxwell Chen
-
class A { public: A() {} A(const A& t) { std::cout << "Copy ctor\n"; /* ... */ } operator = (A& r) { std::cout << "Assignment ctor\n"; /* ... */ } }; void f() { A aa; A bb = aa; // Copy ctor is used. A cc; cc = aa; // Assignment ctor is used. } Maxwell Chen
thanx 4 replying maxwell r u seen my question these think i know thanx
-
thanx 4 replying maxwell r u seen my question these think i know thanx
In the book "The C++ Programming Language, 3rd Ed" by Stroustrup, page 246, The fundamental reason is that a copy constructor initializes uninitialized memory, whereas the copy assignment operator must correctly deal with a well-constructed object. Maxwell Chen