C ++ basic function code example

Source: Internet
Author: User

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:

 
 
  1. // A non-standard String class of the string class, which is a class created by an individual. No copy constructor is defined.
  2. String a = "GG"; // allocate a heap
  3. Local scope {
  4. String B = a; // error. a shared heap is generated when copying by members.
  5. } // The local scope ends and the Destructor B. ~ Is called .~ String (), the heap space is deleted
  6. // 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

 
 
  1. X::X (const X& right){  
  2. copy(right);  

Value assignment operator overloading for C ++ basic functions

 
 
  1. X& X::operator=(const X& right){  
  2. if (this !=&right){  
  3. free();  
  4. copy(right);  
  5. }  
  6. return *this;  

Analysis of C ++ basic functions
 

 
 
  1. X::~X(){  
  2. free()  

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.