本文介绍了PTHREAD_MUTEX_INITIALIZER里面的C ++成员函数不能编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class A {
public:
A();
private:
pthread_mutex_t mu;
};
A::A()
{
mu = PTHREAD_MUTEX_INITIALIZER; //cannot compile
}
无法初始化 pthread_mutex_t
Can't I initialize pthread_mutex_t
inside a class member function?
推荐答案
而不是这样:
A::A()
{
mu = PTHREAD_MUTEX_INITIALIZER; //cannot compile
}
尝试:
A::A()
{
pthread_mutex_init( &(mu), NULL);
}
PTHREAD_MUTEX_INITIALIZER是一个宏, 0,0,0,0 {0}},只能在定义点使用。
The PTHREAD_MUTEX_INITIALIZER is a macro,a C struct initializer for something like {0,0,0,0,0{0}} and can only be used at the point of definition.
这篇关于PTHREAD_MUTEX_INITIALIZER里面的C ++成员函数不能编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!