C++ "::" without class name [duplicate] - c++

This question already has answers here:
scope resolution operator without a scope
(6 answers)
Closed 5 years ago.
I came across the following code structure in C++:
uint32_t AClass::Action(....)
{
..
status = ::Action(...);
..
}
I am not sure what ::Action() means. Which class does it belongs to? NOTE: the argument list of ::Action(...) is different from AClass::Action(...).

The leading :: just means that Action here refers to a non-member function in the global namespace, instead of referring to AClass::Action in the current namespace.

::Action() mean it is a function under the the global namespace.

Related

What is the meaning of multiple class methods separated by "::"? [duplicate]

This question already has answers here:
What does the "::" mean in C++?
(4 answers)
Closed last year.
I found this line of code where I'm working, but I don't quite understand its meaning:
virtual method1::method2::method3 f() = 0;
In the main function, I have method1::method2::method3.g1().g2(). I really don't understand. I know method::A where A is a class.
:: is a scope operator.
You may need to append multiple of them either when using nested classes (a class defined within another class) or when you use namespaces. Resolution is done the same way.
:: is the scope resolution operator. It allows you to statically traverse scopes such as namespaces and classes in order to reference the identifier you want.
I think what you have is not methods but namespaces and classes.

Can I use the static keyword for classes and structs in C++? [duplicate]

This question already has answers here:
Superiority of unnamed namespace over static?
(2 answers)
Closed 2 years ago.
I understand that you can use the static keyword for functions and variables to prevent them from being visible from other files. Can I use it for classes/structs? For example, inside a function, I use a struct that only that function uses, but I don't want to be able to use it from outside that file and I don't return that struct.
Can I use the static keyword for classes and structs in C++?
No. However, you can define classes in an anonymous namespace which will prevent it from being named in other translation units.

Can a static variable be access by nonstatic functions? [duplicate]

This question already has answers here:
Can Non-static function modify a static variable in c++
(3 answers)
Closed 4 years ago.
My questions is: if a static variable (access level: private) is defined in a class and we want to access it by non static function of that class. . is it possible in c++?
The answer is yes.
This question was already somewhat asked here: Can non-static methods modify static variables
You are just asking if it can access it though - I am fairly certain if you can modify something, that means you can also access it.

Object declaration with preceding :: in C++ [duplicate]

This question already has answers here:
What's the purpose of a leading "::" in a C++ method call
(2 answers)
Closed 6 years ago.
What does following represent in C++?
::SomeNameSpace::SomeClass abc;
Basically how is this different from
SomeNameSpace::SomeClass abc;
The :: operator is the scope operator; it denotes some specific scope. If there is no prefix then it denotes the global scope.
So if SomeNameSpace is in the global scope, then ::SomeNameSpace and SomeNameSpace are the same. The difference is if you're in a non-global scope and use SomeNameSpace, because then it's first looked for in the current scope.

what does "::functionName()" imply in c++? [duplicate]

This question already has answers here:
What is the meaning of prepended double colon "::"?
(9 answers)
:: without a namespace
(3 answers)
Why is :: (scope) used with empty left-hand operand? [duplicate]
(6 answers)
Closed 9 years ago.
I came across a piece of code which looks like this:
::GetSystemDirectory(buffer, MAX_PATH);
I've never seen a function call preceded by an empty ::. I've always seen them being used with namespaces.
Can someone please explain me what does an empty :: mean ?
It's the scope resolution operator. With nothing in front of it, it indicates global scope.
So for instance, suppose you have a class that defines its own GetSystemDirectory method. Within the code of a method of that class, to call the global one, you'd need the :: in front of it, otherwise by default you'd get the one specific to the class. (And similarly for namespaces.)