成员方法声明中的* static *关键字的位置 [英] the position of the *static* keyword in member method declaration

查看:127
本文介绍了成员方法声明中的* static *关键字的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class C {
    static int func();
};

class C {
    int static func();
};

我试图删除其他人的代码库中的关键字 static

I'm trying to remove the keyword static in someone else's code base. And I want to make sure I understand what the second example means before I do that.

删除静态的原因:C是一个没有成员变量和充满静态方法的类。我认为更合适的是使C命名空间与正常的函数,而不是一个类。

The reason to remove static: C was a "class" with no member variables and full of static methods. I think it's more proper to make "C" a namespace with normal functions instead of a class.

推荐答案

没有区别。函数声明上的 static 适用于函数。

这个指针不会被隐式传递给这个函数,所以你不能访问非静态类成员里面的这个函数没有显式地传递对象到它。

There is no difference. static on the function declaration applies to the function.
An this pointer will not be implicitly passed to this function, So you cannot access non static class members inside this function without explicitly passing the object to it.

要删除 static 首先你应该知道和理解它是这样设计的目的。没有考虑到你只是必然创造一个巨大比例的代码气味。

To remove the static first you should know and understand the purpose that it is designed this way. Without taking that in to consideration you are just bound to create a code smell of vast proportions.

这篇关于成员方法声明中的* static *关键字的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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