gpt4 book ai didi

c++ - Boost 1.44.0 + VS2010 私有(private)成员报错

转载 作者:行者123 更新时间:2023-11-30 01:30:53 26 4
gpt4 key购买 nike

我在 Utils.h 中有一个类声明:

    class Utils {
private:
static boost::mutex outputMutex;
};

在cpp文件中:

boost::mutex Utils::outputMutex = boost::mutex();

我得到:

Error 1 error C2248: 'boost::mutex::mutex' : cannot access private member declared in class 'boost::mutex'

如果我们查看 boost/thread/win32/mutex.hpp,我们会看到:

namespace boost
{
class mutex:
public ::boost::detail::underlying_mutex
{

// ...

public:
mutex()
{
initialize();
}

有谁知道我在这里缺少什么?以前用VS2008在不同机器上编译OK。

谢谢。

最佳答案

你拥有的是复制初始化,相当于:

boost::mutex Utils::outputMutex(boost::mutex());

调用复制构造函数。但是,mutex 是不可复制的。让它默认构造:

boost::mutex Utils::outputMutex;

关于c++ - Boost 1.44.0 + VS2010 私有(private)成员报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3983588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com