由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教boost::any compile错误。
相关主题
C++一个string的小问题question about structure initializationa and reference
a string define question (c++)array allocation in c
这段C++代码有啥问题在 windows下的C++开发平台是不是 Dev-C++?
why do we still use dynamic allocation?effective C++里的memory pool 一问:
compile errorwhy int** cannot convert to const int** ?
make 时候遇到 undefined reference 怎么办?[合集] 一个指针的小问题
一个c++小问题请教一个用gsl库的问题
形参可以直接使用私有数据成员?What're the three types of memory allocated for C++ variables?
相关话题的讨论汇总
话题: boost话题: std话题: any话题: valuetype
进入Programming版参与讨论
1 (共1页)
k***p
发帖数: 115
1
我的compiler是gcc 4.7。 多谢
$g++ testAny.cpp -o testAny
testAny.cpp: In function ‘void AnyTesting3()’:
testAny.cpp:66:54: error: no match for ‘operator=’ in ‘myPropertySet.std:
:map<_Key, _Tp, _Compare, _Alloc>::operator[], boost
::any, std::less >, std::allocator std::basic_string, boost::any> > >((* & std::basic_string(((
const char*)"BarrType"), (*(const std::allocator*)(& std::allocator<
char>()))))) = (BarrierType)0u’
testAny.cpp:66:54: note: candidates are:
In file included from testAny.cpp:1:0:
/usr/include/boost/any.hpp:69:15: note: template boost::any
& boost::any::operator=(const ValueType&)
testAny.cpp:66:54: error: template argument for ‘template
boost::any& boost::any::operator=(const ValueType&)’ uses local type ‘
AnyTesting3()::BarrierType’
testAny.cpp:66:54: error: trying to instantiate ‘template > boost::any& boost::any::operator=(const ValueType&)’
In file included from testAny.cpp:1:0:
/usr/include/boost/any.hpp:75:15: note: boost::any& boost::any::operator=(
boost::any)
/usr/include/boost/any.hpp:75:15: note: no known conversion for argument 1
from ‘AnyTesting3()::BarrierType’ to ‘boost::any’
程序:
#include
#include
#include
#include
#include
void AnyTesting3()
{
enum BarrierType{ DownAndOut, UpAndIn, DownAndIn, UpAndOut};
std::map myPropertySet;
myPropertySet["domRate"]=0.003;
myPropertySet["forRate"]=0.031;
myPropertySet["Name"]=std::string("Barrier Option");
myPropertySet["BarrType"] =BarrierType(DownAndOut);
}
d****i
发帖数: 4809
2
Change the last line to
myPropertySet["BarrType"] = BarrierType::DownAndOut;
And then compile it using the -std switch
g++ -I/usr/local/boost_1_55_0 -o boost_any -std=c++0x boost_any.cpp
OR
g++ -I$BOOST_ROOT -o boost_any -std=c++0x boost_any.cpp
It should compile.

std:
boost

【在 k***p 的大作中提到】
: 我的compiler是gcc 4.7。 多谢
: $g++ testAny.cpp -o testAny
: testAny.cpp: In function ‘void AnyTesting3()’:
: testAny.cpp:66:54: error: no match for ‘operator=’ in ‘myPropertySet.std:
: :map<_Key, _Tp, _Compare, _Alloc>::operator[], boost
: ::any, std::less >, std::allocator: std::basic_string, boost::any> > >((* & std::basic_string(((
: const char*)"BarrType"), (*(const std::allocator*)(& std::allocator<
: char>()))))) = (BarrierType)0u’
: testAny.cpp:66:54: note: candidates are:

1 (共1页)
进入Programming版参与讨论
相关主题
What're the three types of memory allocated for C++ variables?compile error
数组指针的问题make 时候遇到 undefined reference 怎么办?
急,VC7.1编译错误一个c++小问题
const char *p, is it ok to change p[1] ?形参可以直接使用私有数据成员?
C++一个string的小问题question about structure initializationa and reference
a string define question (c++)array allocation in c
这段C++代码有啥问题在 windows下的C++开发平台是不是 Dev-C++?
why do we still use dynamic allocation?effective C++里的memory pool 一问:
相关话题的讨论汇总
话题: boost话题: std话题: any话题: valuetype