When shoud "::mFunc()" syntax be used?
Hello,
Assuming we have an object "spb", which has a member function named "getsize".
Now I want to invoke the "getsize" function. Could some one explain to me the difference between the following 2 methods:
-------method 1------------
::getsize();
-------method 2------------
spb test;
test.getsize();
-------------------------------
How are the two methods used under different circumstances ?
Thanks very much in advance,
Scope resolution operator
Yes indeed,
The double colon operator is called the scope resolution operator which is used to resolve namespace and certain class/structure elements. The simple double colon prefix is the scope resolution operator applied on global scale. Static functions not belonging to any class or namespace can be resolved with this.
The sample below explains all this a bit more clearly.
Chris.
:)
Code:
class c
{
public:
static void nothing(void) { }
};
void nothing(void)
{
}
namespace notta
{
void nothing(void)
{
}
}
int main(int argc, char* argv[])
{
// Global function nothing()
::nothing();
// Member function nothing()
::c::nothing();
// Namespace function nothing()
::notta::nothing();
return 1;
}