I have a class written by a 3rd party, which has something like this Foo.h:
class Foo
{
public:
int Foo::dosomething(float x, float y, float z);
//Other things here
};
And in Foo.cpp, dosomething is:
int Foo::dosomething(float x, float y, float z)
{
//Something
}
What does the ::
before the function name in the header mean? When I create a new object
Foo foo;
I cannot access the dosomething function like this:
foo.dosomething(1,2,3);
How is dosomething meant to be accessed? When I remove the :: in the header file before dosomething like so:
class Foo
{
public:
int dosomething(float x, float y, float z);
//Other things here
};
I can access dosomething from an object of type Foo.
In general, it is not illegal to use the
::
scope operator against the existing class scope to refer to its own members (even though it is redundant).The problem is that the definition of point of declaration seems to preclude using the scope operator in the member declaration if it is on its own name.
There are no exceptions for class members in the paragraphs that follow in the rest of §3.3.2.
Even with the above restriction, the syntax for class members do not prohibit the use of a qualified-id for the member name. It is therefore not a syntax error to accept the shown code. But, there is a semantic violation, and a diagnostic should have been emitted.