Week 3 L 2&3
Week 3 L 2&3
Week 3 L 2&3
Programming (OOP)
Week 3
Constructor
Note: Even if we do not
define any constructor
explicitly, the compiler will
automatically provide a
default constructor
implicitly.
2. Parameterized Constructors
If we don’t define our own copy constructor, the C++ compiler creates a default
copy constructor for each class which does a member-wise copy between objects
The compiler created copy constructor works fine in general. We need to define
our own copy constructor only if an object has pointers or any runtime allocation
of the resource like file handle, a network connection..etc.
Shallow Copy Vs Deep Copy
Shallow Copy of object if some variables are defined in heap memory, then:
Demo Example