Given a pointer to a C++ object, what is the preferred way to call a static member function?

前端 未结 7 1861
挽巷
挽巷 2020-12-21 04:56

Say I have:

class A {
public:
    static void DoStuff();

    // ... more methods here ...
};

And later on I have a function that wants to

7条回答
  •  天涯浪人
    2020-12-21 05:08

    Although I agree that A::DoStuff() is clearer, and it's what I'd write myself, I can see an argument for going via the pointer, which is "suppose the class name changes". If class A becomes class B, then we only need to update the class name in one place (the pointer declaration) instead of two.

    Just a thought...

提交回复
热议问题