提高::任何库不编译:“使用数组作为初始化”错误(boost::any library doesn&

2019-10-21 00:14发布

我使用boost::any一个C ++项目(其他升压功能中)。

下面编译与G ++我的Mac(运行最新版本的小牛的MacBook Pro的Retina)就好了:

#include <boost/any.hpp>

但是当我使用Ubuntu Linux操作系统使用g ++使用相同的编译设置/标志,我得到以下错误:

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>语句。

我使用的是G ++ 4.9,从崇高的文本3与Ubuntu 14.04。

这是一个加速的问题还是什么?

谢谢你的帮助!

更新:

由于TC使用了他的“精神力量”来预测,我是想投字符串字面量boost::any 。 现在代码工作通过在经历后,并把一些字符串文字的string构造和编辑了一些相关的功能。

Answer 1:

我的精神力量说,你正试图把一个字符串字面里面boost::any 。 这是不允许的; 字符串文字的数组const char和数组不是CopyConstructible ,这boost::any要求。

代替

boost::any t("foo");

采用

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

迫使阵列衰减到一个指针,或

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

使其存储std::string代替。



文章来源: boost::any library doesn't compile: “Array used as initializer” error
标签: c++ boost c++14