#include <iostream> #include <string>using namespace Std;class phone{public:phone (string name); Virtual ~ Phone () {cout<< "Phone Destory" <<ENDL;} virtual void print (); string GetName () {return m_name;} Private:string M_name;}; Phone::P Hone (string name): M_name (name) {cout<< "Phone create" <<ENDL;} void Phone::p rint () {cout<< "Phone name:" <<M_NAME<<ENDL;} Class Iphone:public Phone{public:iphone (string name, bool Issiri = 1); ~iphone (); iphone (const iphone& RHS); iphone & operator= (const iphone& RHS), virtual void print ();p Rivate:bool m_bissiri;};i Phone::iphone (string name, bool Issiri):P Hone (name), M_bissiri (Issiri) {cout<<getname () + "create" <<ENDL;} Iphone::iphone (const iphone& RHS):P Hone (RHS)//base copy function {cout<< "copy func" <<endl;m_bissiri = rhs.m _bissiri;} iphone& iphone::operator= (const iphone& RHS) {cout<< "operator= func" <<endl; Phone::operator= (RHS);//base Assignment Operation M_bissiri = Rhs.m_bissiri;return *this;} Iphone::~iphone () {cout<<getname () + "Destory" <<ENDL;} void Iphone::p rint () {cout<< "I Am" << "" + GetName (); if (M_bissiri) {cout<< "and I have Siri" <<endl ;} else{cout<< "And I had not Siri" <<ENDL;}} int main () {phone* pphone = new iphone ("iphone");pP Hone->print ();d elete pphone;pphone = new iphone ("HTC", 0);pP hone-& Gt;print ();d elete pphone;pphone = null;iphone iphone ("iphone"), iphone HTC ("HTC"); HTC = Iphone;//operator=htc.print (); iphone Samsung (HTC);//copy constructor Samsung.print (); return 1;}
Effective C + + 12 code