英文解释:

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. :( Call to a member function Table() on a non-object 错误位置

    :( Call to a member function Table() on a non-object 错误位置 $Model不是模板,是你自己先前链接数据库返回的对象...我的是改为$Form

  2. Fatal error: Call to a member function on a non-object 的2种解决办法

    这两天被一个莫名其妙的错误:Fatal error: Call to a member function on a non-object in d://www/htdocs/inc.php 77  搞 ...

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

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

  4. static 和 no static Member function学习

    以下是做实验的一段代码: #include <iostream> using namespace std; typedef void (*p)(); class Object { publ ...

  5. Function语义学之member function

    之前我们讲过编译器会对 nonmember functions 进行怎样的扩充和该写,今天我们来讲一下 member functions 函数调用方式 一.Nonstatic Member Funct ...

  6. About The Order of The Declarations And Definition When Making a Member Function a Friend.关于使类成员成为另一个类友元函数的声明顺序和定义。

    If only member function clear of WindowMgr is a friend of Screen, there are some points need to note ...

  7. how to get address of member function

    see:http://www.cplusplus.com/forum/general/136410/ & http://stackoverflow.com/questions/8121320/ ...

  8. C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)

    4.4 指向Member Function的指针 (Pointer-to-Member Functions) 取一个nonstatic data member的地址,得到的结果是该member在 cl ...

  9. Thinkphp---------Call to a member function free_result() on a non-object

    1.平时用框架用久了,直接执行原生的sql反而做起来反应迟钝了.今天遇到一个问题,就是直接执行一个添加的sql语句,然后我用了TP框架的M()->query();方法.运行以后,会报Call t ...

随机推荐

  1. 两张Excel表比较,两个for循环比较优化使用Contains

    将一个Excel表中的sheet中的一列导出到List<string>,用一个for循环循环另一张表中的数据,看是否在第一张表中的Contains中

  2. 递归函数(Day15)

    一.递归的定义 在一个函数里面再调用这个函数本身 递归特性 1.必须有一个明确的结束条件 2.每次进入更深一层递归时,问题规模相比于上一次的递归有所减少 二.递归的应用 1.递归函数与三层菜单 men ...

  3. mapInfo文件格式详解

    from:http://hotolee.blog.163.com/blog/static/3815229920098434956370 MapInfo以表(Tab)的形式存储信息,每个表是由一组Map ...

  4. LeetCode:数据库技术【175-178】

    LeetCode:数据库技术[175-178] LeetCode已经刷完200道题目,但这只是开始,下一段时间,仍然把刷题作为重点,争取再次完成200道,本篇博客将会带大家熟悉一些数据库面试题,从简单 ...

  5. PHP下使用Redis消息队列发布微博

    phpRedisAdmin :github地址  图形化管理界面 git clone [url]https://github.com/ErikDubbelboer/phpRedisAdmin.git[ ...

  6. javascript;json数据,js转换日期方法。

    接收json数据,日期格式为:"\/Date(1414078309687)\/" var value = "/Date(1414078309687)/"; va ...

  7. [Papers]Finding Advertising Keywords on Web Pages

    参考资料: Finding Advertising Keywords on Web Pages ,Wen-tau Yih,Joshua Goodman, Vitor R. Carvalho

  8. Python编程-多进程一

    一.python并发编程之多进程 1.multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在pyth ...

  9. 封装一个既能遍历数组又能遍历对象的的forEach函数

    function newforEach(obj,fn) { var key; if(obj instanceof Array){ obj.forEach(function(item,index){ f ...

  10. c++ boost库学习一:时间和日期

    timer类 #include <boost\timer.hpp> #include "iostream" using namespace std; int _tmai ...