Home

The other way to use con/destructor

Classes that unallowed to Copy If you wanna simulate a country and you can just get a president, and President class will be in danger! 1234President ourPresident;DoSomething(ourPresident);//duplicat

move constructor

In some cases, object will be copied automatically: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566class Mystring{ pri

Copy Constructor

For a Function Area(), argument passed is copied: 1Double Area(double radius); So, when invoking Area(), argument is copied to parameter ‘radius’, the rule can also be used in ‘object’(instance of cl

Destructor

When and how to use destructor? 123456~Mystring(){ cout << "invoking destructor, clearing up" << end; if(buffer != NULL) delete [] buffer;} Whenever an object is out of scope o

Constructor

Declaration of Constructor 1234class Human{ Human(); //declaration of a constructor}; Implementation of Constructor The first case: Implementation in class 1234567class Human{

const -> pointer

Const was used with Pointer. The first case: The address which Pointer contained is a Constant, Can’t be changed, but you can change the Data pointed to: 12345int daysInMonth = 30;int * const pDaysIn

dec、hex、oct

cout利用控制符dec、hex、oct分别输出dec、hex、out进制,具体哪个是哪个你查查字典吧~ 123456789101112131415void (){​ int a = 42;​ cout<<"a = "<<a<<endl;​ cout<<hex; //十六进制​ cout<<"a = "&l