Tutorial by Examples

The Assignment Operator is when you replace the data with an already existing(previously initialized) object with some other object's data. Lets take this as an example: // Assignment Operator #include <iostream> #include <string> using std::cout; using std::endl; class Foo { ...
Copy constructor on the other hand , is the complete opposite of the Assignment Constructor. This time, it is used to initialize an already nonexistent(or non-previously initialized) object. This means it copies all the data from the object you are assigning it to , without actually initializing the...
Ok we have briefly looked over what the copy constructor and assignment constructor are above and gave examples of each now let's see both of them in the same code. This code will be similar as above two. Let's take this : // Copy vs Assignment Constructor #include <iostream> #include <s...

Page 1 of 1