C ++错误:找不到成员声明 [英] C++ error : Member declaration not found
本文介绍了C ++错误:找不到成员声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个想要在Linux上移植的Windows c ++代码
MyClass.h
I have a windows c++ code i want to port on Linux
MyClass.h
class MyClass
{
private:
#ifdef WIN32
CRITICAL_SECTION _mutex_obj_;
#else
pthread_mutex_t _mutex_obj_;
pthread_mutexattr_t _mutex_obj__attr_;
#endif
protected:
public:
MyClass();
virtual ~MyClass();
};
MyClass.cpp
MyClass.cpp
MyClass::MyClass()
{
#ifdef WIN32
InitializeCriticalSection(&_mutex_obj_);
#else
pthread_mutexattr_init(&_mutex_obj__attr_);
pthread_mutex_init(&_mutex_obj_, &_mutex_obj__attr_);
pthread_mutexattr_destroy(&_mutex_obj__attr_);
#endif
}
MyClass::~MyClass()
{
}
编译后我收到此错误未找到会员声明
感谢先进的
when compiled i get this error Member declaration not found
Thanks in advanced
推荐答案
此代码:
This code:
#ifndef WIN32
#include <pthread.h>
#endif
class MyClass
{
private:
#ifdef WIN32
CRITICAL_SECTION _mutex_obj_;
#else
pthread_mutex_t _mutex_obj_;
pthread_mutexattr_t _mutex_obj__attr_;
#endif
protected:
public:
MyClass();
virtual ~MyClass();
};
MyClass::MyClass()
{
#ifdef WIN32
InitializeCriticalSection(&_mutex_obj_);
#else
pthread_mutexattr_init(&_mutex_obj__attr_);
pthread_mutex_init(&_mutex_obj_, &_mutex_obj__attr_);
pthread_mutexattr_destroy(&_mutex_obj__attr_);
#endif
}
MyClass::~MyClass()
{
}
int main()
{
MyClass mc;
}
在我的Ubuntu盒子上编译(并运行)正常(不要忘记链接 pthread
library)。
compiles (and runs) fine on my Ubuntu box (don't forget to link with pthread
library).
这篇关于C ++错误:找不到成员声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文