[RK_2014_1020]Cannot declare member function ‘static int Foo::bar()’ to have static linkage

1.

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.

2.本文网址[tom-and-jerry发布于2014-10-20 18:02]

http://www.cnblogs.com/tom-and-jerry/p/4037965.html

时间: 2024-10-16 15:13:39

[RK_2014_1020]Cannot declare member function ‘static int Foo::bar()’ to have static linkage的相关文章

C++ 之 const member function

一个常量成员函数(const member function), 可以读取类的数据成员,但不能修改类的数据成员. 1  声明 在成员函数声明的参数列表后,加上 const 关键字,将其声明为常量成员函数(const member function),表明其不被允许修改类的数据成员 下面定义了一个 Date 类,分别以年.月.日的形式来表示日期 class Date { public: int day() const { return d; } int month() const { return

Virtual Member Functions & Static Member Function

如果一个 normalize() 是一个 virtual member function, 那么以下的调用: ptr->normalize(); 将会被内部转化为: (*ptr->vptr[1])(ptr); 其中:vptr 表示由编译器生成的指针, 指向 virtual table, 它被安插在每一个声明有(或继承自) virtual functinos 的 class object 中. 事实上其名称也会被 mangled, 因为在一个复杂的 class 派生体系中, 可能存在多个 vpt

static 和 no static Member function学习

以下是做实验的一段代码: #include <iostream> using namespace std; typedef void (*p)(); class Object { public: static void s_fun_1() { cout << "static function 1\n"; } void fun_1() {cout << "no static function 1\n";} }; typedef vo

invalid use of non-static member function ‘void Date::init(int, int, int)’

#include<iostream> using namespace std; class Date { public: int day,month,year; void init(int,int,int); void print_ymd(); }; void Date::init(int yy, int mm, int dd) { year = yy; month = mm; day = dd; } void Date::print_ymd() { std::cout << ye

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

4.4 指向Member Function的指针 (Pointer-to-Member Functions) 取一个nonstatic data member的地址,得到的结果是该member在 class 布局中的byte位置(再加1),它是一个不完整的值,须要被绑定于某个 class object的地址上,才可以被存取. 取一个nonstatic member function的地址,假设该函数是nonvirtual,则得到的结果是它在内存中真正的地址.然而这个值也是不全然的,它也须要被绑定

&#39;init&#39;:member function definition looks like a ctor(构造函数的缩写)

具体编译的错误提示如下:warning C4183: 'init': member function definition looks like a ctor, but name does not match enclosing classwarning C4183: 'method': member function definition looks like a ctor, but name does not match enclosing classLinking...main.exe -

Timer.4 - Using a member function as a handler

In this tutorial we will see how to use a class member function as a callback handler. The program should execute identically to the tutorial program from tutorial Timer.3. #include <iostream> #include <boost/asio.hpp> #include <boost/bind.

C++ - 模板类模板成员函数(member function template)隐式处理(implicit)变化

模板类模板成员函数(member function template)隐式处理(implicit)变化 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24233693 指针支持隐式转换(implicit conversion), 在动态绑定中,派生类指针能够转换为基类指针. 可是模板的实例化(instantiations)之间, 是单独存在的, 派生类的实例化的模板(SmartPtr<Derived>), 不能转换为基类实例

Fatal error: Call to a member function read() on a non

选模版时报错如下:Fatal error: Call to a member function read() on a non-object inC:\wamp\www\DedCms5.7\include\dialog\select_templets.php on line 71或者是/include//templets/default/index.htm Not Found!95%的导致原因是本地测试好了之后上传到服务器的路径问题!解决方法:后台->系统->系统基本设置->核心设置 -