Exactly. That's what the scope resoulution operator is for.
C++ has function overloading. That is, more than than one function can have the same name. However, at the same time, all function names must be unique in order for the compiler and linker to operate.
So, each function name is preceded with a scope resolution operator and that is preceded by the name of the scope, such as a class name.
MyClass::main() is the main function inside the MyClass class.
Xyz::main() is the main function inside the Xyz class.
::main() is a function that has no named scope. This is the main() that is outside any scope. That is, the freestanding or global main(). This is the main() the linker is looking for. This is the main that has to be in every program.
- int ::main() //the global main()
-
{
-
MyClass obj;
-
obj.main(); //calls MyClass::main()
-
obj.MyClass::main(); //does the same as the preceding line.
-
}