List of constructor parameters for C + +

Source: Internet
Author: User

Referenced from: 78122485

    • Constructor's default constructor (the calling constructor does not pass parameters)
Both instantiation methods are default constructors
    • Initialization list of constructors
The Scarlet Letter section is the initialization list: A quotation mark, multiple parameters separated by commas, and an assignment () to initialize the list attribute:
  1. Its first in constructor execution
  2. It can only be used for constructors
  3. It can initialize multiple data members at the same time
    • "Note" The function of the initialization list: for static constants in a class that cannot be initialized with constructors, you must use the initialization list
    • Copy constructor
Features of the copy constructor:
      1. When the user does not have a constructor defined, the compiler automatically generates a default copy constructor (as well as a constructor)
      2. The copy constructor is automatically called when instantiating an object with direct initialization or replication initialization
      3. Because of the nature of the copy constructor, the copy constructor cannot be overloaded!!
    • Summarize constructor Summary:
    • "Summary" When all parameters have default values, they are converted to default constructors
"Note" The initialization list is available for all constructors.
    • Destructors (functions for freeing system resources)
      Define the format:


      Destructor Features:
      • If you do not have a custom destructor, the system automatically generates
      • Destructors are called automatically when an object is destroyed (corresponding to which the constructor is automatically called when the object is instantiated)
      • Destructors do not have return values (the same is true for constructors), no parameters, and cannot be overloaded
      • Do not allow any parameters to be added within ()
    • The life course of "important knowledge point" object
      • Classification of "Summary" member functions

        Parameter decoration method of member function

        How objects are instantiated

        Define a function as long as it is not a function declaration, remember to write {}, even if {} does not write any statements.

Summary: The order in which constructors and destructors are called

1. Execute the constructor of the grouped object first

(1) When a class has a member variable that is an object of another class, the constructor for the member variable is called first, the invocation order is the same as the declaration order, and then the constructor of the class is called.

(2) The order of the destructors is called in the opposite order of the corresponding constructor calls.

2, the construction order of the grouped objects, the predefined order has a relationship, and the order of the initialization list is not related

3. Special member variables must be initialized with a parameter list. const, &, Object .

4. A member variable of typestatic must be initialized outside of the class without the static keyword.

List of constructor parameters for C + +

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.