Copy constructor is called whenever an object is copied and new object has to be created with the same data. This happens when you say foo = bar, but also when you pass the object as a parameter to a function by value, i.e calling foo(bar) where bar isn't a reference or pointer.
The = operator can also handle other types like assigning an int to your object, or a different object to your object. Like you can do this by overloading the = operator but not with the copy constructor.
int foo;
YOUROBJECT bar;
bar = foo;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment