当全局变量之前使用static关键字? [英] When to use static keyword before global variables?

查看:206
本文介绍了当全局变量之前使用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;

如果这有静态常量或不前?问:使用静态的一些最佳实践

推荐答案

静态呈现局部变量通常是一件好事文件,例如见的这个维基百科条目

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

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

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