给定一个指向C ++对象的指针,调用静态成员函数的首选方法是什么? [英] Given a pointer to a C++ object, what is the preferred way to call a static member function?

查看:110
本文介绍了给定一个指向C ++对象的指针,调用静态成员函数的首选方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有:

class A {
public:
    static void DoStuff();

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

稍后我有一个函数要调用DoStuff:

And later on I have a function that wants to call DoStuff:

B::SomeFunction(A* a_ptr) {

最好说:

    a_ptr->DoStuff();
}

或者是下面更好的,即使我有一个实例指针:

Or is the following better even though I have an instance pointer:

    A::DoStuff()
}

这是纯粹的风格问题,但我想在作出决定之前得到一些知情的意见。

This is purely a matter of style, but I'd like to get some informed opinions before I make a decision.

推荐答案

我想我更喜欢A :: DoStuff(),因为更清楚的是静态方法正在被调用。

I think I'd prefer "A::DoStuff()", as it's more clear that a static method is being called.

这篇关于给定一个指向C ++对象的指针,调用静态成员函数的首选方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆