002 OOPs using C++ with Eclipse on LinuxDiscussion Forum for Programming with C++. We introduce to programming in general, including object-oriented programming and generic programming. It is also a solid introduction to the C++ programming language, one of the most widely used languages for real-world software. This Training presents modern C++ programming techniques from the start, introducing the C++ standard library to simplify programming tasks.
Scope resolution operator defines that the function belongs to a particular class, and can only be accessed by the objects of that particular class. Objects of other classes can not access that function, unless it is used as a friend function.
So, if class name is Box, and function name is func(); then the definition goes like this:
The Scope Resolution Operator (::) in C++ enables us to access variables, functions, or classes defined in different scopes.
Purpose of use this operator 1) To access a global variable when there is a local variable with same name. 2) To define a function outside a class. 3) To access a class’s static variables. 4)In case of multiple Inheritance. 5)Refer to a class inside another class. Etc Eg #include using namespace std;
class outside { public: int a; class inside { public: int a; static int c; int foo(); }; }; int outside::inside::c= 5;
int main() { outside obj1; outside::inside obj2; }