C + + double colon:: The role of

Source: Internet
Author: User

  1. Scope symbol:: The front of the general is the class name, followed by the class is generally the member name, C + + as an example to avoid different classes have the same name of the member and the scope of the way to differentiate
    For example: A, B represents two classes, and a member is member in a A, B. So
    A::member represents a member of Class A member
    B::member represents a member in Class B member
  2. global scope Symbol: When a global variable has the same name as one of the variables in a local function, you can use:: To distinguish between :

    Char Zhou; Global Variables

    void Sleep ()

    {

    Char Zhou; Local Variables

    char (local variable) = char (local variable) *char (local variable);

    :: char (global variable) =::char (global variable) *char (local variable);

  3. :: Is the scope decomposition operator in C + +. For example, a Class A is declared, a member function VOIDF () is declared in Class A, but no definition of f is given in the declaration of the class, so the definition of F outside the class is written as Voida::f (), which means that the F () function is a member function of Class A. For example
1 classCA2 {3   Public:4       intCa_var;5       intAddintAintb);6       intAddinta); 7 };8 9 //So when you implement this function, you have to write thisTen intCa::add (intAintb) One { A        returnA +b;  - } -  the //In addition, a double colon is often used to represent an element within a class variable as the current class instance, such as: - intCa::add (inta) - { -        returnA +:: Ca_var_;//represents the variable Ca_var in the current class instance. +}

C + + double colon:: The role of

Related Article

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.