"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 ...
随机推荐
- Python之函数总结
一,函数的定义与调用 定义:def 关键词开头,空格之后接函数名称和圆括号(),最后还有一个":". def 是固定的,不能变,必须是连续的def三个字母,不能分开 def 函数名 ...
- LeetCode:路径总和【112】
LeetCode:路径总和[112] 题目描述 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例 ...
- Hibernate多对多关联
多对多关联: 示例:Teacher和Student,一个Teacher可以教很多student,一个Student也可以被很多teacher教 多对多单向关联 Teacher知道自己教了哪些学生, ...
- qnx 黑莓系统
qnx 黑莓图形系统框架 http://www.360doc.com/content/07/0807/10/38907_658192.shtml http://blog.csdn.net/keyboa ...
- 【Head First Servlets and JSP】笔记17:JSP所生成的servlet相关问题
1.容器根据你所写的JSP生成一个类, /* * Generated by the Jasper component of Apache Tomcat * Version: Apache Tomcat ...
- P3794 签到题IV
题目 P3794 签到题IV 来切道水题放松一下吧 做法 或是单调不下降的,\(gcd\)是单调不上升的 \(a_i≤5×10^5\)分成权值不同的块数应该很小,所以随便乱搞就出来了 My compl ...
- pagination结合ajax
function getContent(page,Id){ $.ajax({ type:'get', url:'www.baidu.com', dataType:'jsonp', data:{ }, ...
- 2017最全的php面试题目及答案总结
最近在网上看到很多的小伙伴们都在询问如何应对php面试,这个对于有工作经验和实战项目的小伙伴来说是没什么问题的,但是对于刚刚学习完php的小伙伴们.php面试却是一个很重要的一步,那么今天php中文网 ...
- iOS上架被拒原因及解决办法
简单的记录一下,近期APP上架所遇到的坑爹事儿吧!! 第一次提交: 第二天给了回复,内容如下: .Guideline - Performance - Software Requirements You ...
- 默认连接电脑的模式为MTP【转】
本文转载自:https://blog.csdn.net/tangzhihai0421/article/details/53487208 Android L后默认的usb连接模式为“仅充电”,而且不会随 ...