Static Function

I can call static function by class object, why its valid?

Static functions are class level, we call them with class name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Test
{
    private:
        int _a;
    public:
        static Display()
       {
         // Display Code
       }
};

int main()
{
  Test obj;
  Test::Display();          // 1. call static function by class name
  obj.Display();            // 2. call static function by class instance
}


Is there any difference in calling static function in above two ways?

Is any useful situation where we need to call static function by class insance?

Please replay. :)
Is there any difference in calling static function in above two ways?
Standard says, no, there is no difference:
A static member s of class X may be referred to using the qualified-id expression X::s; it is not necessary to use the class member access syntax (5.2.5) to refer to a static member. A static member may be referred to using the class member access syntax, in which case the object expression is evaluated.


Is any useful situation where we need to call static function by class insance?
I do not see situations where using the class member access syntax would be preferable.
Topic archived. No new replies allowed.