英文解释:

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
       };
};

Cannot declare member function ...to have static linkage错误相关推荐

  1. static用法报错解决:cannot declare member function to have static linkage [-fpermissive]

    1.test.h 定义 class Test{static Test* GetInstance(); //.h文件中的Test类,加static属于Test类区域的范围static CameraHar ...

  2. 提示illegal reference to data member'CPMAgentManageDlg::m_matrixMatrixSt'in a static member function

    当提示"illegal reference to data member'CPMAgentManageDlg::m_matrixMatrixSt'in a static member fun ...

  3. c++ 静态类成员函数(static member function) vs 名字空间 (namespace)

    好多人喜欢把工具函数做成static member function.这样以增加隐蔽性和封装性,由其是从C#,java转而使用c++的开发人员. 例如: class my_math { public: ...

  4. 出现错误illegal call of non-static member function?

    当出现错误"illegal call of non-static member function"? 解决方法:原因在于没有经过对象,就调用了非静态成员函数,只有静态成员函数(st ...

  5. C/C++编程:reference to non-static member function must be called

    主要原因是我使用了函数指针,而函数指针所指函数须得是静态才行 错误代码: class Solution {public:string ReverseSentence(string str) {type ...

  6. invalid use of non-static member function

    现在有一个 Object 类,它有两个方法: Recv 负责接收数据,并传递给 Process Process 负责处理数据 我们希望这个类接收完数据后启动线程去处理,不阻塞后面的其他业务逻辑. cl ...

  7. 错误信息:cannot call member function ‘ ‘ without object 处理

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 一.源码展示 总结 提示:以下是本篇文章正文内容,下面案例可供参考 一.源码展示 std::vectorstd::strin ...

  8. [Error] cannot call member function ‘‘ without object

    今天遇到一个错误 [Error] cannot call member function 'int Computer::getCnt()' without object 意思是不能在没有对象的情况下, ...

  9. 成员函数指针与高性能的C++委托 (Member Function Pointers and the Fastest Possible C++ Delegates)...

    标准C++中没有真正的面向对象的函数指针.这一点对C++来说是不幸的,因为面向对象的指针(也叫做"闭包(closure)"或"委托(delegate)")在一些 ...

  10. Keil5报错:error: more than one instance overload function “xx“ has C linkage

    转自:https://blog.csdn.net/malloc_luo/article/details/104437926 用Keil编写C.C++混编程序碰到了这个问题 #ifdef __cplus ...

最新文章

  1. 百度编辑器(ueditor)上传图片
  2. 无法打开文件“python310_d.lib”
  3. 判断密文加密类型hash-identifier
  4. 怎么用python画简单的图-python中简单易学的绘图:用turtle画太极图
  5. 欧司朗台灯的灯泡容易坏是怎么回事
  6. 交叉验证中n_jobs=-1并行运算
  7. 今晚直播:WLS/WAS故障基本分析介绍
  8. LLVM每日谈之一 LLVM是什么
  9. python百题百练 二级题目_计算机二级选择题(公共基础新大纲)
  10. 面向对象java试题_经典面向对象试题,用Java做,要详细点的!先谢过了
  11. java qq音乐接口 api,GitHub - yan123zi/qqMusicApi: qq音乐Api接口
  12. 实体消歧(链接到实体库)
  13. AtCoder Beginner Contest 167 Solution
  14. matlab 精品课程,同济大学经济与管理学院精品课程
  15. matlab求三维图形表面积,基于MATLAB的不规则平面立体表面积计算
  16. 如何导入后缀ndm的文件
  17. 麦子学院学习视频之机器学习(1):1.1 机器学习介绍
  18. project和program的区别
  19. linux版本beyond compare 4 的30天试用期已过-解决方法
  20. 计算机仿真技术(2)

热门文章

  1. 蓝桥杯2021年第十二届C++省赛第四题-货物摆放
  2. 覆盖的面积 HDU - 1255 (扫描线, 面积交)
  3. Django model 反向引用中的related_name
  4. C#限制float有两位小数
  5. mysql5.6.31安装及配置
  6. 201521123115 《Java程序设计》第3周学习总结
  7. 3D游戏常用技巧Normal Mapping (法线贴图)原理解析——基础篇
  8. Java线程状态的改变
  9. 原码、反码、补码解析及其简单转化
  10. Cocos2d-x特殊节点对象(瓦片地图、粒子系统、视差滚动)概述