I have some c++ code that I am analyzing and I came across something I don't know what it means.
I have a class like this
class A
{
public:
int I;
void function();
}
void A::function()
{
cout << A::I;
}
Neither the function nor I is declared static in the class.
I don't understand the scope of I in the function. Is it the member of the instance that "function" is called from? Or is a static member? I've never seen the variable accessed in that manner from inside the class its a member from.
There is nothing to try, is a C++ specification question
This function
is a non-static member of the class.
You may use qualified names of members of the class like
to distinguish members from for example local variables of a function.
Let's assume that the function is declared and defined like
In this function the parameter has the same name as the data member. You can write as shown above to distinguish the parameter and the data member or you could write
From the C++ 17 Standard (6.4.3.1 Class members)
In the original function definition you can omit the class name because there is no ambiguity. The qualified name in this case is only used for documentation purpose.