Many important functions in the C ++ programming language play a very important role in our actual program development. Here we will summarize three commonly used basic C ++ functions. You can have a comprehensive understanding of the functions in C ++ programming language.
- C ++ parameter transfer
- Connect C ++ to the SQL database in steps
- Basic concepts of C ++ Chinese and English strings
- Basic Content of C ++ namespace
- C ++ breakpoint invalid Solution
When talking about destructor, almost all reference books around me use only a little space without exception, but Big C ++ is really rare to hit the key once
Quality tip 18.4: if there is a destructor, there should also be three basic functions: copy constructor and assign value operator)
For classes that manage heap memory, these three functions must be implemented
Example:
- // A non-standard String class of the string class, which is a class created by an individual. No copy constructor is defined.
- String a = "GG"; // allocate a heap
- Local scope {
- String B = a; // error. a shared heap is generated when copying by members.
- } // The local scope ends and the Destructor B. ~ Is called .~ String (), the heap space is deleted
- // At this time, the heap space of a has been deleted by the destructor of B.
Common construction modes:
Copy constructor of C ++ basic functions
- X::X (const X& right){
- copy(right);
- }
Value assignment operator overloading for C ++ basic functions
- X& X::operator=(const X& right){
- if (this !=&right){
- free();
- copy(right);
- }
- return *this;
- }
Analysis of C ++ basic functions
- X::~X(){
- free()
- }