Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I'm trying to serialize shared pointer using boost but it gives error :
Error 1 error C4308: negative integral constant converted to unsigned type c:\users\mydirect\future\lib\boost_1_55_0\boost\mpl\print.hpp 51 1 Input

Spent more than 2 days on this but no clue.. when i comment line "ar & MyInfo" error does not come so it means surely issue is with shared pointer.. how do i go ahead.

Below is the code :

// MyData.hpp file
struct MyData
{
std::string id;
std::string name;
boost::shared_ptr<mydata> Mydata;

private:
friend class boost::serialization::access;
template<class archive="">
void serialize(Archive &ar, const unsigned int version)
{
ar & id;
ar & name;
ar & Mydata;
}

public:
MyData(void);
MyData(const parameter_strings & parms);

virtual ~MyData(void);
};
}

// MyData.cpp file

MyData::MyData(void)
{
}

MyData::~MyData(void)
{
}

MyData::MyData(const parameter_strings & parms)
{
// implementation aprt
}

BOOST_CLASS_EXPORT_IMPLEMENT(MyData); BOOST_CLASS_IMPLEMENTATION(MyData,boost::serialization::object_serializable);
BOOST_CLASS_TRACKING(MyData,boost::serialization::track_selectively);
Posted
Comments
The_Inventor 22-Mar-14 22:52pm    
From your .hpp file your are missing and end bracket } from your 'struct MyData' structure, and then within the structure you have called out your shared pointer with the same name. This can cause an error.

However the error code is specifying line 51 in 'Print.hpp' first input as the issue.

1 solution

I think the cleaned version below will be more workable. The error code refers to Print.hpp line 51 first input.

C++
// MyData.hpp file

typedef struct tagMyData
{
    std::string id;
    std::string name;
    boost::shared_ptr ptMydata;

public:
    MyData(void);
    MyData(const parameter_strings& parms);
    virtual ~MyData(void);
 
private:
 friend class boost::serialization::access;

 template
 void serialize(Archive &ar, const unsigned int version)
 {
    ar &id;
    ar &name;
    ar &ptMydata;
    ar &version; 
 } 
} MyData;

  
 // MyData.cpp file
  
 MyData::MyData(void)
 {
 }
  
 MyData::~MyData(void)
 {
 }
  
 MyData::MyData(const parameter_strings & parms)
 {
 // implementation aprt
 }
  
 BOOST_CLASS_EXPORT_IMPLEMENT(MyData); BOOST_CLASS_IMPLEMENTATION(MyData,boost::serialization::object_serializable);
 BOOST_CLASS_TRACKING(MyData,boost::serialization::track_selectively);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900