What does the "::" function represent in c++? Please describe how it works.
In C++ :: is termed as the scope resolution operator. It has the following vert crucial and important functions to perform:
1) It enables a function to be defined outside the class.
We consider the following code snippet:
class MyClass
{
public:
void Demo(); //We declare the function Demo in class
};
void Demo::MyClass();
{
//statements
}
//Here we declared the function Demo outside the main class. This is done using the scope resolution operator.
2) It enables us to access those variables of a class which are declared as static
3) In cases of conflicts, when we have a local and a global variable both having same name, the scope resolution operator distinguishes between them both
Get Answers For Free
Most questions answered within 1 hours.