Let's take notes first:
The content of this class is about
- constructor function
- Destructors
- Operator overloading
- return * This
The content is very fine, everybody reviews the note to take care of the procedure review:)
#include <iostream>using namespacestd;classInteger { Public: inti; intGeti ()Const{return This-i;} voidSETI (inti) { This->i =i;} Integer (intj =0); Integer (Integer&c); ~Integer ();};i Nteger::integer (Integer& c) {//Constructer Functioni = -; cout<<"Integer (integer & C)"<<Endl;} Integer::integer (intJ): I (j) {//Copy constructer Functioncout <<"Integer (int j)"<<Endl;} Integer::~integer () {//Destructer Functioncout <<"~integer ()"<<Endl;}ConstInteger & Fun (ConstInteger &inch) {cout<<inch. Geti () <<Endl; return inch;}intMain () {Integer B (8); Fun (b). Geti (); Integer A (b); return 0;}
The following program is about operator overloading
Log print allows you to track the order in which the destructors are observed
There are also examples of reference returns, friend functions
#include <iostream>using namespacestd;classInteger {Private: inti; Public: intGeti ()Const{return This-i;} voidSETI (inti) { This->i =i;} Integer (intj =0); Integer (Integer&c); ~Integer (); ConstInteger &operator= (ConstInteger &inch); FriendConstIntegeroperator+ (ConstInteger & LHS,ConstInteger &rhs);};ConstInteger & Integer::operator= (ConstInteger &inch) {//Member Functioni =inch. i + -; //return in; return* This;}ConstIntegeroperator+ (ConstInteger & LHS,ConstInteger & RHS) {//Global FunctionsInteger out; out. i = lhs.i +rhs.i; return out;} Integer::integer (Integer& c) {//Constructer Functioni = -; cout<<"Integer (integer & C)"<<Endl;} Integer::integer (intJ): I (j) {//Copy constructer Functioncout <<"Integer (int j)"<<' '<< J <<Endl;} Integer::~integer () {//Destructer Functioncout <<"~integer ()"<<' '<< I <<Endl;}intMain () {Integer B (8), A, C, D; cout<<"A.geti ()"<< A.geti () <<Endl; D= c = A =b; cout<<"A.geti ()"<< A.geti () <<Endl; cout<<"C.geti ()"<< C.geti () <<Endl; cout<<"D.geti ()"<< D.geti () <<Endl; D= A +b; cout<<"D.geti ()"<< D.geti () <<Endl; return 0;}
Object-Oriented Programming-c++ Default constructor & Copy constructor& destructor & Operator Overloading "Nineth lesson Notes"