#include #include #include using namespace std; //myClassCopyConstructor4.cpp // assign one instance (object) to other. class Base { private : int pvtn1; string pvtstr1; int x; public: Base() { cout<<"\n default constructor "; } Base(int n1) { pvtn1 = n1; cout<<"\n \t\b integer constructor : " << pvtn1; } Base(string str1) { pvtstr1 = str1; cout<<"\n \t\b string constructor : " << pvtstr1; } Base(Base ©Base1 ) ; Base(Base ©Base1,Base ©Base2 ) ; }; //copy constructor with logistics // will separate integer from string Base::Base(Base ©Base1 ) { if(copyBase1.pvtn1 == 20) { cout<<"\n constructor integer type " ; pvtn1= copyBase1.pvtn1; cout<<"\n \t integer copy consturctor : "<< pvtn1; } // if(copyBase1.pvtstr1!=""){ cout<<"\n constructor string type " ; pvtstr1 = copyBase1.pvtstr1; cout<<"\n \t string copy consturctor "<< pvtstr1; } } Base::Base(Base ©Base2,Base ©Base3 ) { pvtn1= copyBase2.pvtn1; pvtstr1 = copyBase3.pvtstr1; cout<<"\n \t joint integer copy consturctor : "<< pvtn1; cout<<"\n \t joint string copy consturctor : "<< pvtstr1; } int main() { Base _bse; Base base(20); // integer constructor. can serve as an id Base base1("January"); // string constructor cout<<"\n ---------------"; Base cbase0(base);// Base cbase1(base1); cout<<"\n ---------------"; Base cbase2(base, base1);// copy constructor cout<<"\n ---------------"; Base base11("February"); // copy constructor cout<<"\n ---------------"; cout<<"\n assign will include everything including garbage"; base1 = base11; // will override base1 Base cbase3(base1); return 0; }