"Cannot declare member function ...to have static linkage"错误
英文解释: 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"错误的更多相关文章
- :( Call to a member function Table() on a non-object 错误位置
:( Call to a member function Table() on a non-object 错误位置 $Model不是模板,是你自己先前链接数据库返回的对象...我的是改为$Form
- 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 搞 ...
- c++ 静态类成员函数(static member function) vs 名字空间 (namespace)
好多人喜欢把工具函数做成static member function.这样以增加隐蔽性和封装性,由其是从C#,java转而使用c++的开发人员. 例如: class my_math { public: ...
- static 和 no static Member function学习
以下是做实验的一段代码: #include <iostream> using namespace std; typedef void (*p)(); class Object { publ ...
- Function语义学之member function
之前我们讲过编译器会对 nonmember functions 进行怎样的扩充和该写,今天我们来讲一下 member functions 函数调用方式 一.Nonstatic Member Funct ...
- 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 ...
- how to get address of member function
see:http://www.cplusplus.com/forum/general/136410/ & http://stackoverflow.com/questions/8121320/ ...
- C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)
4.4 指向Member Function的指针 (Pointer-to-Member Functions) 取一个nonstatic data member的地址,得到的结果是该member在 cl ...
- Thinkphp---------Call to a member function free_result() on a non-object
1.平时用框架用久了,直接执行原生的sql反而做起来反应迟钝了.今天遇到一个问题,就是直接执行一个添加的sql语句,然后我用了TP框架的M()->query();方法.运行以后,会报Call t ...
随机推荐
- 3.6中的range()
在python3中range()是这样的: >>> range(4) range(0, 4) #额,列表跑哪去了 在之前的python2中是这样的: >>> ran ...
- SPOJ - HORRIBLE 【线段树】
思路 线段树 区间更新 模板题 注意数据范围 AC代码 #include <cstdio> #include <cstring> #include <ctype.h> ...
- Spring AOP 学习(一) 代理模式
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程(也叫面向方面),可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- P4317 花神的数论题
题目 洛谷 数学方法学不会%>_<% 做法 爆搜二进制下存在\(i\)位\(1\)的情况,然后快速幂乘起来 My complete code #include<bits/stdc++ ...
- MySQL-LRU_List Free_List Flush_List
关于 LRU_List ,Free_List,Flush_List的介绍: LRU算法:(Latest Recent Used)最近最少使用 数据库的缓冲池通过LRU算法来进行管理. ...
- 【转载】关于C++中cin的几点说明性总结
转载地址:http://www.07net01.com/program/289153.html 学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结: 1.cin 2.cin.get() 3.ci ...
- iostream与iostream.h的区别
简单来说: .h的是标准C的头文件,没有.h的是标准C++的头文件,两种都是头文件. 造成这两种形式不同的原因,是C++的发展历史决定的,刚才正好有别的人也问这个问题,这里我再回答一下(注意vs200 ...
- HDU 2603 二分匹配
#include <queue>#include <vector>#include <cstdio>#include <cstring>#include ...
- 如何隐藏tomcat命令窗口
有两种方法: 一.修改tomcat中的文件参数,达到隐藏目的: 引用:TOMCAT_HOME\bin\setclasspath.bat 在文件的底部找到以下内容: set _RUNJAVA=" ...
- MySQL/MariaDB数据库备份与恢复之mysqlpump入门操作
创建测试用表:MariaDB [music]> create table summary(id int,info char(128));Query OK, 0 rows affected (0 ...