I am very new to C++ and found the following Code example.
Can the "::" operator be used in this way and why or should it only be used for declared namespaces?
class Test {
void dosmthng();
};
void Test::dosmthng() {}
I am very new to C++ and found the following Code example.
Can the "::" operator be used in this way and why or should it only be used for declared namespaces?
class Test {
void dosmthng();
};
void Test::dosmthng() {}
The ::
operator is called the Scope Resolution Operator
.
Names declared inside the class are related to the class scope
.Searching for names for class scope is subject to some rules.
If the name is used within a global function, the name must be used in one of 3 cases for the name to be searched in class scope.
point operator
. (.)arrow operator
. (->)scope resolution operator
. (::)The 3 important processes and sequences related to name searching are as follows.
Name Lookup
=>
name is searched first.
Context Control
=> Other rules of the language . For example, mistakes like using Rvalue where Lvalue is needed.
Access Control
=> A separate category of controls in Object Oriented programming languages. It is done at compile time.
The left operand of the scope resolution operator must be a name in C++.This name can be a namespace name, it can be a class name.Right operand if class name it will be searched in the scope of that class. To summarize, it is one of the important operators of the language used for name lookup.