Use of colon of: and double colon of :: in c++
- 2020-04-02 01:11:41
- OfStack
(1) the definition of bit domain in the mechanism (that is, the variable occupies several bit Spaces)
(2) the colon after the constructor plays the role of segmentation, which is a method for the class to assign values to the member variables, initializes the list, and is more suitable for the constant const type of the member variables.
(3) the colon after public: and private: indicates that all members defined later are public or private until the next "public: "or "private:" appears. Private :" is the default.
(4) after the colon of the class name is used to define the inheritance of the class.
Public, private, and protected. The default is public.
2. Double colon (::) usage
(1) represents "domain operator"
Example: declared A class A, class A declared A member function void f(), but did not give the definition of f in the declaration of the class, so the definition of f outside the class,
I'm going to write void A::f(), which means that f() is A member of class A.
(2) directly used in front of the global function, the expression is a global function
Example: in VC, you can call the API function in the API function, before the name of the API function: :
(3) refers to the reference member function and variable, 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, if A class A is declared and A member function voidf() is declared in class A, but the definition of f is not given in the declaration of the class, then when f is defined outside the class, it should be written as voidA::f(), indicating that this f() function is A member function of class A.
:: there is a general use, is directly used in front of the global function, the expression is a global function. When a member function of a class has the same name as a global function outside the class, when defined in the class, the member function is called by default. If you want to call a global function with the same name, you must type :: to distinguish it. For example, in VC, you can call API function, before the API function name:.
typedef struct _XXX{
unsigned char a:4;
unsigned char c;
} ; XXX
(2) the colon after the constructor plays the role of segmentation, which is a method for the class to assign values to the member variables, initializes the list, and is more suitable for the constant const type of the member variables.
struct _XXX{
_XXX() : y(0xc0) {}
};
(3) the colon after public: and private: indicates that all members defined later are public or private until the next "public: "or "private:" appears. Private :" is the default.
(4) after the colon of the class name is used to define the inheritance of the class.
class Derived class name : Inheritance way The base class name
{
A member of a derived class
};
Public, private, and protected. The default is public.
2. Double colon (::) usage
(1) represents "domain operator"
Example: declared A class A, class A declared A member function void f(), but did not give the definition of f in the declaration of the class, so the definition of f outside the class,
I'm going to write void A::f(), which means that f() is A member of class A.
(2) directly used in front of the global function, the expression is a global function
Example: in VC, you can call the API function in the API function, before the name of the API function: :
(3) refers to the reference member function and variable, 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, if A class A is declared and A member function voidf() is declared in class A, but the definition of f is not given in the declaration of the class, then when f is defined outside the class, it should be written as voidA::f(), indicating that this f() function is A member function of class A.
:: there is a general use, is directly used in front of the global function, the expression is a global function. When a member function of a class has the same name as a global function outside the class, when defined in the class, the member function is called by default. If you want to call a global function with the same name, you must type :: to distinguish it. For example, in VC, you can call API function, before the API function name:.