2013-05-25 16 views
9

benim yapı:boost seri uyarı C4308: negatif ayrılmaz sabit işaretsiz türe dönüştürülür

struct member{ 
     std::string ip_address; 
     std::string port; 

    protected: 
     friend class boost::serialization::access; 

     template<class Archive> 
     void serialize(Archive & ar, const unsigned int version) 
     { 
      ar & ip_address; 
      ar & port; 
     } 
    }; 

Kurtarmam ve bunun olmasını bekliyoruz gibi tüm veriler, mükemmel çalışıyor yüklemek için kullanabilir,

std::vector<member> members; 
std::ostringstream ss; 
boost::archive::text_oarchive oa(ss); 
oa<<members; 


std::istringstream ss_(received_data.data()); 
boost::archive::text_iarchive ia(ss_); 
ia>>members; 

ama derleme üzerinde ki burada olmanıza

warning C4308: negative integral constant converted to unsigned type 
1>  c:\program files\boost\boost_1_51\boost\serialization\static_warning.hpp(92) : see reference to class template instantiation 'boost::mpl::print<T>' being compiled 
1>  with 
1>  [ 
1>   T=boost::serialization::BOOST_SERIALIZATION_STATIC_WARNING_LINE<98> 
1>  ] 
1>  c:\program files\boost\boost_1_51\boost\archive\detail\check.hpp(98) : see reference to class template instantiation 'boost::serialization::static_warning_test<B,L>' being compiled 
1>  with 
1>  [ 
1>   B=false, 
1>   L=98 
1>  ] 
1>  c:\program files\boost\boost_1_51\boost\archive\detail\oserializer.hpp(313) : see reference to function template instantiation 'void boost::archive::detail::check_object_tracking<T>(void)' being compiled 
1>  with 
1>  [ 
1>   T=std::vector<member> 
1>  ] 
1>  c:\program files\boost\boost_1_51\boost\archive\detail\oserializer.hpp(525) : see reference to function template instantiation 'void boost::archive::detail::save_non_pointer_type<Archive>::invoke<T>(Archive &,T &)' being compiled 
1>  with 
1>  [ 
1>   Archive=boost::archive::text_oarchive, 
1>   T=std::vector<member> 
1>  ] 
1>  c:\program files\boost\boost_1_51\boost\archive\detail\common_oarchive.hpp(69) : see reference to function template instantiation 'void boost::archive::save<Archive,T>(Archive &,T &)' being compiled 
1>  with 
1>  [ 
1>   Archive=boost::archive::text_oarchive, 
1>   T=std::vector<member> 
1>  ] 
1>  c:\program files\boost\boost_1_51\boost\archive\basic_text_oarchive.hpp(80) : see reference to function template instantiation 'void boost::archive::detail::common_oarchive<Archive>::save_override<T>(T &,int)' being compiled 
1>  with 
1>  [ 
1>   Archive=boost::archive::text_oarchive, 
1>   T=std::vector<member> 
1>  ] 
1>  c:\program files\boost\boost_1_51\boost\archive\detail\interface_oarchive.hpp(63) : see reference to function template instantiation 'void boost::archive::basic_text_oarchive<Archive>::save_override<T>(T &,int)' being compiled 
1>  with 
1>  [ 
1>   Archive=boost::archive::text_oarchive, 
1>   T=std::vector<member> 
1>  ] 
1>  c:\users\user\desktop\shve\shve\member_server.h(58) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive<Archive>::operator <<<std::vector<_Ty>>(T &)' being compiled 
1>  with 
1>  [ 
1>   Archive=boost::archive::text_oarchive, 
1>   _Ty=member, 
1>   T=std::vector<member> 
1>  ] 
+0

Yani, soru nedir? –

+0

Neden uyarıyı alıyorum? Nasıl çözebilirim? –

+0

Diğer derleyicilerle aynı sebepten başka bir uyarı üretilebilir. clang ile: 'include/boost/mpl/print.hpp: 50: 23: uyarı: sıfır ile bölünme undefined [-Wdivision-by-zero]' – maxschlepzig

cevap

16

Boost sinirli bu uyarıyı almak archiving non-const class instances Farklı izlenen nesnelerin aynı adresi kullanması durumunda, 'un nesne izlemede bir soruna neden olabilir.

Eğer const için nesneyi düşürebilir uyarıyı kaldırmak için:

oa << const_cast<const std::vector<member>&>(members); 

Veya sadece & operatörünü kullanabilirsiniz: Bu özellikle uyarı kaynağını oldu

oa & members; 

(ve ortak) durum. Genel olarak, bu tür derleyici uyarısı, BOOST_STATIC_WARNING makrosuna yapılan bir çağrı ile Boost tarafından üretilir ve bu nedenle, Boost'un dikkatli olmanızı istediği herhangi bir şey olabilir. Bu genellikle, makro çağırma (derleyici hata iletinizden bulabileceğiniz) ekine eşlik eden bir yorumda dile getirilir. Örneğin, bu özel uyarının çağrısı, boost\archive\detail\check.hpp:

+0

Hm, artıranın sebebi nedir? Operatör bu bağlamda kullanmak daha güvenli? Bir alternatif (bazı kullanım durumları için) belki de 'BOOST_CLASS_TRACKING' (boost :: serialization :: track_never) 'işlevini kullanmaktır - ör. nesneleri yığından serileştirirken. – maxschlepzig

+0

Başvurulan açıklamayı izledim, ancak hala ne yapacağımı bilmiyordum - Bu yorumun '&' operatörüne referans olmasını diliyorum. – sage

İlgili konular