Archive: 2021/4

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{