Colon in C + + (:) and double colon (::) usage description _c language

Source: Internet
Author: User
(1) denotes the definition of an institution's inner-field (that is, the variable takes up several bit spaces)
Copy Code code as follows:

typedef struct _xxx{
unsigned char a:4;
unsigned char c;
} ; Xxx

(2) The colon at the back of the constructor splits, the method that the class assigns to the member variable, initializes the list, and is more applicable to the constant const type of the member variable.
Copy Code code as follows:

struct _xxx{
_xxx (): Y (0xc0) {}
};

(3) Public: and private: The following colon, which means that all the members that are defined later are publicly or privately owned, until the next, or private:, appears. "Private:" for default processing.
(4) After the class name colon is used to define the inheritance of the class.
Copy Code code as follows:

Class derived class Name: Inheritance method base class name
{
Members of derived classes
};

Inheritance: Public, private, and protected, and default processing is public.
2. Double colon (::) usage
(1) denotes "field operator"
Example: Declares a Class A, Class A declares a member function void F (), but does not give the definition of F in the declaration of the class, then the f is defined outside the class.
It is written as a void A::f (), which means that the F () function is a member function of class A.

(2) Directly before the global function, the expression is a global function
For example: In VC, you can call API functions in the API function name before adding::

(3) refers to reference member functions and variables, the scope member operator
Example: System::math::sqrt () is equivalent to SYSTEM.MATH.SQRT ()

VC in the following
:: Is the "scope decomposition operator" in C + +. For example, declaring a Class A, Class A declares a member function VOIDF (), but does not give the definition of F in the declaration of the class, then the definition of f in the class is written as Voida::f (), which means that the F () function is a member function of Class A.

:: There is generally a use, is directly used in the global function before, the expression is a global function. When a member function of a class has the same name as a global function outside of a class, the test, when the big hint is defined within the class, calls the function name by default as its own member functions; If you want to invoke a global function of the same name, you must hit:: To make a difference. For example, in VC, you can call API functions in the API function name before adding::.
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.