#include <boost/any.hpp>
#include <list>
#include <string>
#include <vector>
struct _time_t {
int month;
int year;
};
int main()
{
std::string str = "hahastr";
_time_t t;
std::vector<boost::any> objVec;
objVec.push_back(1);
char* pstr = "haha";
//boost::any charArr = "haha"; not compile
//objVec.push_back("haha"); not compile
objVec.push_back(pstr);
objVec.push_back(str);
objVec.push_back(t);
return 0;
};
注释的代码行无法编译,为什么?我认为字符串文字在大多数情况下可以充当 char*,这是相关的 r-value 和 l-rvalue 吗?
错误信息:test_boost_any.cc
D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\xlocale(336) : wa
rning C4530: C++ exception handler used, but unwind semantics are not enabled. S
pecify /EHsc
e:\projects\framework\boost_1_53_0\boost/any.hpp(122) : error C2536: 'boost::any
::holder<ValueType>::boost::any::holder<ValueType>::held' : cannot specify expli
cit initializer for arrays
with
[
ValueType=const char [5]
]
e:\projects\framework\boost_1_53_0\boost/any.hpp(139) : see declaration
of 'boost::any::holder<ValueType>::held'
with
[
ValueType=const char [5]
]
e:\projects\framework\boost_1_53_0\boost/any.hpp(120) : while compiling
class template member function 'boost::any::holder<ValueType>::holder(ValueType
(&))'
with
[
ValueType=const char [5]
]
e:\projects\framework\boost_1_53_0\boost/any.hpp(47) : see reference to
function template instantiation 'boost::any::holder<ValueType>::holder(ValueType
(&))' being compiled
with
[
ValueType=const char [5]
]
e:\projects\framework\boost_1_53_0\boost/any.hpp(46) : see reference to
class template instantiation 'boost::any::holder<ValueType>' being compiled
with
[
ValueType=const char [5]
]
test_boost_any.cc(19) : see reference to function template instantiation
'boost::any::any<const char[5]>(ValueType (&))' being compiled
with
[
ValueType=const char [5]
]