2013-05-25 4 views
9

내 구조체 :부스트 직렬화 경고 C4308 : 음의 정수 상수는 부호없는 형식으로 변환

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; 
     } 
    }; 

내가 저장하고 나는 그것을 할 예상대로 모든 데이터가 완벽하게 작동로드를 사용

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; 

하지만 컴파일에 나는 당신이 것을

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

그래서, 문제는 무엇인가? –

+0

경고를받는 이유는 무엇입니까? 어떻게 해결합니까? –

+0

다른 컴파일러를 사용하면 같은 원인으로 다른 경고가 생성 될 수 있습니다. include/boost/mpl/print.hpp : 50 : 23 : 경고 : 0으로 나누기가 정의되지 않음 [0으로 나누기]' – maxschlepzig

답변

16

부스트 긴장이 경고를 얻을 archiving non-const class instances 어느 다른 추적 된 개체가 동일한 주소를 사용하는 경우 개체 추적에 문제가 발생할 수 있습니다.

당신이 CONST에 개체를 캐스팅 할 수있는 경고를 제거하려면 다음

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

또는 당신은 단순히 & 연산자를 사용할 수 있습니다 :이 특히 경고의 소스를했다

oa & members; 

(일반적인 경우). 일반적으로이 유형의 컴파일러 경고는 Boost가 BOOST_STATIC_WARNING 매크로를 호출하여 의도적으로 생성되므로 Boost가주의해야 할 사항이 될 수 있습니다. 이것은 일반적으로 매크로 호출에 수반되는 주석 (컴파일러 오류 메시지에서 찾을 수 있음)에서 설명합니다. 예를 들어, 특정 경고에 대한 호출은 boost\archive\detail\check.hpp에서 온 :

// saving an non-const object of a type not marked "track_never) 
// may be an indicator of an error usage of the 
// serialization library and should be double checked. 
// See documentation on object tracking. Also, see the 
// "rationale" section of the documenation 
// for motivation for this checking. 

BOOST_STATIC_WARNING(typex::value); 
+0

흠, 부스트가' '연산자가 그 맥락에서 사용하는 것이 더 안전합니까? 대안은 (어떤 유스 케이스의 경우) 아마도'BOOST_CLASS_TRACKING (boost :: serialization :: track_never)'을 사용하는 것입니다. 스택에서 객체를 직렬화 할 때. – maxschlepzig

+0

나는 참조 된 설명을 추적했지만 여전히 무엇을 해야할지 전혀 몰랐다. 그 주석에'&'연산자에 대한 참조가 포함되기를 바란다. – sage