boost ::任何库都没有编译:"数组用作初始化程序"错误

时间:2014-09-19 23:18:30

标签: c++ boost c++14

我在C ++项目中使用boost::any(以及其他Boost功能)。

以下用g ++编译我的Mac(MacBook Pro Retina运行最新版本的Mavericks)就好了:

#include <boost/any.hpp>

但是当我使用相同的编译设置/标志使用带有g ++的Ubuntu Linux时,我收到以下错误:

In file included from /home/alexandergunnarson/Documents/Source Code/byu/library/collections.cpp:11:0,
                 from /home/alexandergunnarson/Documents/Source Code/byu/library/collections.h:4,
                 from /home/alexandergunnarson/Documents/Source Code/byu/library/main.cpp:16:
/usr/include/boost/any.hpp: In instantiation of ‘boost::any::holder<ValueType>::holder(const ValueType&) [with ValueType = char [5]]’:
/usr/include/boost/any.hpp:52:49:   required from ‘boost::any::any(const ValueType&) [with ValueType = char [5]]’
/home/alexandergunnarson/Documents/Source Code/byu/library/main.cpp:149:22:   required from here
/usr/include/boost/any.hpp:169:27: error: array used as initializer
               : held(value)
                       ^

collections.cpp:11:0指的是#include <boost/any.hpp>声明。

我使用Sublime Text 3中的g ++ 4.9和Ubuntu 14.04。

这是一个提升问题还是什么?

感谢您的帮助!

更新

作为T.C.用过他的心灵力量&#34;为了预测,我试图将字符串文字转换为boost::any。现在代码在经过并在string构造函数中放入一些字符串文字并编辑了一些相关函数之后就可以工作了。

1 个答案:

答案 0 :(得分:5)

我的精神力量表示你试图将一个字符串文字放在boost::any中。这是不允许的;字符串文字是const char的数组,数组不是CopyConstructibleboost::any需要。

而不是

boost::any t("foo");

使用

boost::any t(+"foo");

强制数组衰减为指针,或

boost::any t(std::string("foo")); // or "foo"s in C++14

使其存储std::string

相关问题