confused in static member function of class.
-
hello, I had a confusion that why we can use :: sign in calling static member function of class. while in the case of calling simple member function using :: sign shows error .. in c++. Please explain .
-
hello, I had a confusion that why we can use :: sign in calling static member function of class. while in the case of calling simple member function using :: sign shows error .. in c++. Please explain .
Member functions need qualifiers in order for the compiler to know which function your code refers to. In the case of a static function the qualifer must be the class name, since static functions belong to the class: hence
Class::Function()
. For member functions the qualifer must be the instance reference, as non-static functions are attached to individual objects: henceobject.Function()
orobjectpointer->Function()
. -
Member functions need qualifiers in order for the compiler to know which function your code refers to. In the case of a static function the qualifer must be the class name, since static functions belong to the class: hence
Class::Function()
. For member functions the qualifer must be the instance reference, as non-static functions are attached to individual objects: henceobject.Function()
orobjectpointer->Function()
.thank you so much for clearing my doubt