英文解释:

if you declare a method to be static in your .cc file.

The reason is that static means something different inside .cc files than in class declarations It is really stupid, but the keyword static has three different meanings. In the .cc file, the static keyword means that the function isn't visible to any code outside of that particular file.

This means that you shouldn't use static in a .cc file to define one-per-class methods and variables. Fortunately, you don't need it. In C++, you are not allowed to have static variables or static methods with the same name(s) as instance variables or instance methods. Therefore if you declare a variable or method as static in the class declaration, you don't need the static keyword in the definition. The compiler still knows that the variable/method is part of the class and not the instance.

翻译: 

如果在你的.cc文件,你声明的方法是静态的。静态意味着的.cc文件不同于类的声明。
但关键字static有三个不同的含义。
在.cc文件,静态关键字意味着该功能是任何代码该文件外部不可见的。这意味着,你不应该使用静态的.cc文件来定义一个每类方法和变量。
在C ++中,你不能有静态变量或静态方法在实例声明和实例方法中具有相同的名称(S)。
因此,如果你在类声明声明一个变量或方法为静态的,你不需要在定义static关键字在.cc文件。
编译器仍然知道该变量/方法是类的一部分,而不是该实例。 错误的:
Foo.h:
class Foo
{
public:
static int bar();
};
Foo.cc:
static int Foo::bar()
{
// stuff
}
正确的:
Foo.h:
class Foo
{
public:
static int bar();
};
Foo.cc:
int Foo::bar()
{
// stuff
}
这个也是正确的:
Foo.h:
class Foo
{
public:
static int bar()
{
// stuff
};
};

最新文章

  1. TFS 掩蔽或取消掩蔽工作区中的文件夹
  2. Spark常用函数(源码阅读六)
  3. NET中的规范标准注释(一) -- XML注释标签讲解
  4. 用postgreSQL做基于地理位置的app(zz)
  5. [Stephen]自定义SimpleAdapter
  6. java查询手机号码归属地
  7. Appium:通过wifi连接Android设备
  8. C#对象序列化笔记
  9. php-fpm 相关
  10. 一天搞定CSS: CSS选择器优先级--08
  11. JAVA类型擦除
  12. 提高NetBeans的代码提示速度.md
  13. html5 canvas画布尺寸与显示尺寸
  14. 高仿QQ头像截取
  15. 如何书写一篇能看懂的html和CSS代码
  16. 二.Rsync备份服务
  17. Http协议基础及发展历史
  18. innodb_flush_method理解【转】
  19. sql注入解析
  20. Hadoop 新增删除节点

热门文章

  1. 4.2 使用STM32控制MC20发送短信
  2. bootstrap模板
  3. 对称加密&非对称加密
  4. Django:popup弹出框简单应用实例
  5. Nginx -HTTP和反向代理服务器简单配置
  6. 第二篇 Python图片处理模块PIL(pillow)
  7. 学习小程序第三天 WXML语言特性
  8. yii常用操作函数
  9. ggplot2学习总结
  10. 【Topcoder】SRM158 DIV2总结