Function of the domain differentiation symbol (double Colon: :) In C ++

Source: Internet
Author: User

A. Identify the level of the scope B. Identify the class to which the member belongs
C. Define the scope of a member. D. specify the scope.

 

 

Scope Symbol: the class name is generally followed by the member name of the class. c ++ is used as an example to prevent different classes from being distinguished by the scope when they have members with the same name.
For example, a and B indicate two classes. both A and B have members member. So
A: Member indicates the member in Class.
B: Member indicates a member of Class B.

 

 

 

Example of a global scope symbol (double colon)

# Include <stdio. h>

Int COUNT = 0; // global variable 0

Void main ()
{
 
Int COUNT = 10; // local variable 10
 
Printf ("Count = % d \ n", count); // The local variable shields the global variable, so the output result is 10.
{
Int COUNT = 20;

Printf ("Count = % d \ n",: Count); // The scope symbol indicates that the global variable 0 is referenced.
//: Sort
}
}

 

 

 

 

Scope identifier: What does it mean when it is used separately? The following code uses OpenGL in MFC
Int npixelformat =: choosepixelformat (m_hdc, & PFD );
: Setpixelformat (m_hdc, npixelformat, & PFD );
M_hrc =: wglcreatecontext (m_hdc );
: Wglmakecurrent (m_hdc, m_hrc );
What are the meanings of the scope delimiters and those without scope delimiters?
(I tried it and didn't find any difference) Answer:If the namespace NS contains a symbol printf,
There is also a global symbol called printf,
If you use using namespace ns; import the NS symbol, the two printf will conflict. When you only use printf, it will automatically match ns: printf first, so use :: printf refers to the printf in the global symbol.

 

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.