什么时候在全局变量之前使用 static 关键字? [英] When to use static keyword before global variables?

查看:18
本文介绍了什么时候在全局变量之前使用 static 关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下什么时候应该在头文件中定义的全局变量或常量之前使用 static 关键字吗?

Can someone explain when you're supposed to use the static keyword before global variables or constants defined in header files?

例如,假设我有一个包含以下行的头文件:

For example, lets say I have a header file with the line:

const float kGameSpriteWidth = 12.0f;

这是否应该在 const 前面有 static ?使用 static 的最佳实践有哪些?

Should this have static in front of const or not? What are some best practices for using static?

推荐答案

static 渲染本地文件的变量,这通常是一件好事,例如参见 这个维基百科条目.

static renders variable local to the file which is generally a good thing, see for example this Wikipedia entry.

这篇关于什么时候在全局变量之前使用 static 关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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