我想使用boost ::變種矢量
std::vector<boost::variant<mesh::Entity&, mesh::Vertex, mesh::Edge> >
xField::getZeros(const mesh::Region& s, char *EntityS) const
{
//Vertex
if(EntityS == "V")
{
std::vector<mesh::Vertex> zeros;
for(Region::vertexIterator itv = s.beginVertex();
itv != s.endVertex(); ++itv)
{
if(abs(getVal(*itv)) < 1.e-12)
zeros.push_back(*itv);
}
return zeros;
}
else if ..
,但我收到的錯誤: 錯誤:轉換,從「的std :: vector」的非標型「的std ::矢量>」請求
編輯:
zeroVector xField::getZeros(const mesh::Region& s, char *EntityS) const
{
//Vertex
if(EntityS == "V")
{
zeroVector zeros;
for(Region::vertexIterator itv = s.beginVertex(); itv != s.endVertex(); ++itv)
{
if(abs(getVal(*itv)) < 1.e-12)
zeros.push_back(zeroVariant(*itv));
}
return zeros;
和我在h文件的typedef定義
typedef boost::variant<mesh::Entity&, mesh::Vertex, mesh::Edge> zeroVariant;
typedef std::vector<zeroVariant> zeroVector;
,現在我已經得到了以下錯誤:
/softs/boost/1.53.0/64/gcc/4.5.1/include/boost/detail/reference_content.hpp:在成員函數「 void boost :: detail :: variant :: assign_storage :: internal_visit(T &,int)const [with T = boost :: detail :: reference_content]': /softs/boost/1.53.0/64/gcc/4.5 .1/include/boost/variant/detail/visiting_impl.hpp:130:9:從'typename Visitor :: result_type boost :: detail :: variant :: visitation_impl_invoke_impl'實例化(int,Visitor &,VoidPtrCV,T *,mpl_: :true_)[with Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void *,T = boost :: detail :: reference_content,typename Visitor :: re sult_type = void,mpl _ :: true_ = mpl _ :: bool_]' /softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/detail/visitation_impl.hpp:173:9:實例化from'typename Visitor :: result_type boost :: detail :: variant :: visitation_impl_invoke(int,Visitor &,VoidPtrCV,T *,NoBackupFlag,int)[with Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void *,T = boost :: detail :: reference_content,NoBackupFlag = boost :: variant :: has_fallback_type_,typename Visitor :: result_type = void]' /softs/boost/1.53.0/64/gcc/4.5.1/include /boost/variant/detail/visitation_impl.hpp:260:1:實例化來自'typename Visitor :: result_type boost :: detail :: variant :: visitation_impl(int,int,Visitor &,VoidPtrCV,mpl _ :: false_,NoBackupFlag,其中*,step0 *)[其中= mpl _ :: int_ < 0>,step0 = boost :: detail :: variant :: visitation_impl_step,boost :: detail :: re ference_content,boost :: mpl :: l_item,mesh :: Vertex,boost :: mpl :: l_item,mesh :: Edge,boost :: mpl :: l_end >> boost :: mpl :: l_iter >>,Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void *,NoBackupFlag = boost :: variant :: has_fallback_type_,typename Visitor :: result_type = void,mpl _ :: false_ = mpl _ :: bool_]' /softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:2326:13:從靜態類型實例化Visitor :: result_type boost :: variant :: internal_apply_visitor_impl(int,int,Visitor &,VoidPtrCV)[with Visitor = boost :: detail :: variant :: assign_storage,VoidPtrCV = void *,T0_ = mesh :: Entity &,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost: :detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail :: variant :: void_,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: varia nt :: void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_,T17 = boost: :detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,typename Visitor :: result_type = void]' /softs/boost/1.53.0/64/GCC/4.5.1 /包括/升壓/變體/變體。hpp:2337:13:實例化來自'typename Visitor :: result_type boost :: variant :: internal_apply_visitor(Visitor &)[with Visitor = boost :: detail :: variant :: assign_storage,T0_ = mesh :: Entity &,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail :: variant :: void_ ,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant: :void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,typename Visitor :: result_type = void]' /softs/boost /從'void boost :: variant :: variant_assign'(const boost :: variant &)[使用T0_ = mesh的實例化版本:1.53.0/64/gcc/4.5.1/include/boost/variant /variant.hpp:2085:13 :: Entity &,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail:variant :: void_,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant :: void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_ ,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,boost :: variant = boost :: variant] ' /softs/boost/1.53.0/64/gcc/4.5.1/inclu實例化來自'boost :: variant & boost :: variant :: operator =(const boost :: variant &)[with T0_ = mesh :: Entity &,T1 = mesh :: Vertex,T2 = mesh :: Edge,T3 = boost :: detail :: variant :: void_,T4 = boost :: detail :: variant :: void_,T5 = boost :: detail :: variant :: void_ ,T6 = boost :: detail :: variant :: void_,T7 = boost :: detail :: variant :: void_,T8 = boost :: detail :: variant :: void_,T9 = boost :: detail :: variant: :void_,T10 = boost :: detail :: variant :: void_,T11 = boost :: detail :: variant :: void_,T12 = boost :: detail :: variant :: void_,T13 = boost :: detail :: variant :: void_,T14 = boost :: detail :: variant :: void_,T15 = boost :: detail :: variant :: void_,T16 = boost :: detail :: variant :: void_,T17 = boost :: detail :: variant :: void_,T18 = boost :: detail :: variant :: void_,T19 = boost :: detail :: variant :: void_,boost :: variant = boost :: variant]' /usr/include/C++/4.5 /比特/ vector.tcc:312:4:從'void std :: vector < _Tp,_Alloc :: :: M_insert_aux(std :: vector < _Tp,_Alloc> :: iterator,const _Tp &)實例化[with _Tp = boost :: variant ,_Alloc = std :: allocator>,std :: vector < _Tp,_Alloc> :: iterator = __gnu_cxx :: __ normal_iterator *,std :: vector >>,typename std :: _ Vector_base < _Tp,_Alloc> :: _ Tp_alloc_type :: 'void std :: vector < _Tp,_Alloc> :: push_back(const value_type &) [with _Tp = boost :: variant,_Alloc = std :: allocator>,value_type = boost :: variant]' /home/mycode.cc:128:42:從這裏實例化 /softs/boost/1.53.0/ 64/gcc/4.5.1/include/boost/detail/reference_content.hpp:62:24:錯誤:'boost :: detail :: reference_content & boost :: detail :: reference_content :: operator =(const boost :: detail :: reference_content &)[with RefT = mesh :: Entity &,boost :: detail :: reference_content = boost :: detail :: reference_content]'是私人的 /softs/boost/1.53.0/64/gcc/4.5.1/include/boost/variant/variant.hpp:526:9:錯誤:在此範圍內
在此先感謝!!!!!
謝謝,但是當我在.h文件中定義「EvVariantVector xField :: getZeros(const mesh :: Region&s,char * EntityS)const」時,但在.cpp文件中它不能識別「EvVariantVector」以下錯誤:error:'boost :: detail :: reference_content&boost :: detail :: reference_content :: operator =(const boost :: detail :: reference_content &)[with RefT = mesh :: Entity&,boost :: detail :: reference_content = boost :: detail :: reference_content ]''是私人的 –
你把typedef放在哪裏,並且cpp可以看到它?將typedef放入h文件中。 – Pete
剛剛看到你對這個問題的改變... – Pete