得到错误:' this '对于静态成员函数不可用,即使函数不是静态的
Getting error: ‘this’ is unavailable for static member functions even when function is not static
我有功能,在那里我创建新的pthread
,然后使用它以后
void Client::initialize(Client * c) {
//some unimportant code here
pthread_t thread;
pthread_create(&thread, NULL,
c->sendMessage, (void *) fd);
//some unimportant code here
}
Client::Client() {
initialize(this);
}
sendMessage
功能:
void * Client::sendMessage(void *threadid) {
//unimportant code here
this->showHelp();
//unimportant code here
return NULL;
}
showHelp
声明
void Client::showHelp() {
//some code
}
当我尝试编译它时,我得到这个错误:
g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./Client.cpp
./Client.cpp: In static member function ‘static void* Client::sendMessage(void*)’:
./Client.cpp:244:13: error: ‘this’ is unavailable for static member functions
make: *** [Client.o] Error 1
当sendMessage
不声明为static
时,这怎么可能?有别的办法吗?
很可能您的sendMessage
在类定义中被声明为静态。对于静态和非静态函数,特定的成员函数定义是无法区分的。您必须查看类定义来区分它们。
相关文章:
- enable_if转换构造函数(静态强制转换,is_base_of)
- 声明和定义函数静态会产生"undefined reference to function_name()"
- 有没有一种方法可以使全局函数/静态成员函数一次可呼出
- C++ - 模板类 -> 静态函数 -> 静态函数指针的链接错误
- 获取 llvm::函数静态地址
- 成员函数静态变量与成员变量
- 如何将sqlite3+扩展函数静态链接到C/C++应用程序中
- Visual Studio 2015 Natvis如何显示函数静态变量
- 返回一个指向函数静态数据的指针合适吗
- 如何将函数静态应用于非类型模板包的各个元素并对结果求和
- 是否可以通过编程方式创建函数静态对象
- 函数静态变量析构函数和线程
- 函数静态成员变量
- 隐藏模板化的辅助函数——静态成员或未命名的命名空间
- 这个解决方案对MSVC的双重检查锁定错误和函数静态有什么问题?
- 类成员函数静态和私有
- c++函数静态局部,性能好
- 函数静态变量初始化
- 使用基类中的函数静态地调用纯虚函数的派生类实现
- 使成员函数静态会使程序无法编译。想不通为什么