Effective C + + 12 code

Source: Internet
Author: User

#include <iostream> #include <string>using namespace Std;class phone{public:phone (string name); Virtual ~ Phone () {cout<< "Phone Destory" &LT;&LT;ENDL;} virtual void print (); string GetName () {return m_name;} Private:string M_name;}; Phone::P Hone (string name): M_name (name) {cout<< "Phone create" &LT;&LT;ENDL;} void Phone::p rint () {cout<< "Phone name:" &LT;&LT;M_NAME&LT;&LT;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" &LT;&LT;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" &LT;&LT;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" &LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.