提升1.44.0 + VS2010私人会员错误

时间:2010-10-21 01:17:14

标签: c++ visual-studio-2010 boost

我在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。

谢谢。

3 个答案:

答案 0 :(得分:3)

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

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

调用copy-constructor。但是,mutex是不可复制的。让它默认构造:

boost::mutex Utils::outputMutex;

答案 1 :(得分:2)

.cpp文件应为:

boost::mutex Utils::outputMutex;

不需要任务。它将被适当地构建。

答案 2 :(得分:0)

看起来你在类声明中再次声明Utils::outputMutex两次,然后在.cpp中再次声明{{1}}。此外,第二个声明被赋予构造函数的“返回值”,这是不可能的。如果删除第二个声明会怎样?