Writing the Copy Constructor for a Class
This video tutorial made by the Learning Lad explains how to write a copy constructor for a class.
You will learn what are copy constructors, what is the syntax of writing the copy constructors, what is the use of copy constructor, what happens when we copy an object, what problem copy constructor solves in detail with example.
source code for this tutorial
#include#include using namespace std; class Person{ public: string *name; int age; Person(string name,int age){ this->name = new string(name); this->age = age; } Person(const Person &p){ cout << "copy constructor is called "< name) = name; this->age = age; } void introduce(){ cout << "hey i am "<<*name<<" and i am "<