what is the use of :: in them ??
A simple trick, just think of Foo::Bar
as meaning "Bar from Foo". This meaning works everywhere you see those ::
. Like std::cout
is "cout from std namespace". Or MyClass::SomeFunction()
means "call SomeFunction() from MyClass". In fancy C++ terminology, the ::
is called the "scope resolution operator", because in an expression like Foo::Bar
, the operator ::
tells you to what scope Bar
belongs to (i.e., it "resolves" the scope of Bar).
what are member function??
Functions that belong to a class. And when something belongs to a class, it is referred to by something like MyClass::SomeFunction()
, as in, "SomeFunction from MyClass", meaning SomeFunction belongs to MyClass, it is a member function.
what are static and non static member function??
Both types of functions belong to the class (i.e., member functions), but non-static member functions (not declared with the static
keyword) must be called on an object of the class they belong to. Calling it as MyObj.SomeFunction()
means "call SomeFunction on the object 'MyObj'". Calling it as MyObjPtr->SomeFunction()
means "call SomeFunction on the object that 'MyObjPtr' points to". As for static member functions, they are just called by being resolved from the class scope, i.e., as MyClass::SomeFunction()
.
If you are already within the class scope (in the body of a member function, for example), then you don't need to resolve the scope of the static member functions, i.e., no need for the MyClass::
part. If you are …