I should maybe have attached with the message this more reduced code
containing only the problematic classes.
This code fails as previously said during compilation because of the
"loadFromFileSens"
CODE
/*
* SensorReading
*
*/
class Sensor{
public:
Sensor(const std::string& name="");
virtual ~Sensor();
inline std::string getName() const {return m_name;}
inline void setName(const std::string& name) {m_name=name;}
friend class boost::serialization::access;
template <class Archive> void serialize(Archive& ar, const unsigned
int version){
ar & m_name;
}
protected:
std::string m_name;
};
Sensor::Sensor(const std::string& name){
m_name=name;
}
Sensor::~Sensor(){
}
class SensorReading{
public:
SensorReading(const Sensor* s=0, double time=0);
virtual ~SensorReading();
inline double getTime() const {return m_time;}
inline void setTime(double t) {m_time=t;}
inline const Sensor* getSensor() const {return m_sensor;}
inline void print(){
cout << "(" << m_time << "," << m_sensor->getName() << ")" <<
endl;
}
friend class boost::serialization::access;
template <class Archive> void serialize(Archive& ar, const unsigned
int version){
ar & m_time & m_sensor;
}
protected:
double m_time;
const Sensor* m_sensor;
};
SensorReading::SensorReading(const Sensor* s, double t){
m_sensor=s;
m_time=t;
}
SensorReading::~SensorReading(){}
template <class A> void saveIntoFileSens(SensorReading& sr, const char*
file){
ofstream ofile(file);
A ar(ofile);
ar << sr;
ofile.close();
}
template <class A> void loadFromFileSens(SensorReading& sr, const char*
file){
ifstream ifile(file);
A ar(ifile);
ar >> sr;
ifile.close();
}
/*
* MAIN
*
*/
int main(){
Sensor s = Sensor("SensorNom");
SensorReading senr = SensorReading(&s,67);
saveIntoFileSens
Thanks for your quick answer !
But the orientedPoints do work do work perfectly ! (Even without specifying the derived class)
The problem is with the pointer to Sensor* contained in the SensorReading class .... And it seems to me this is not a derived class ....
I'll keep trying ...
----- Original Message ----- From: "Robert Ramey"
Newsgroups: gmane.comp.lib.boost.user To: Sent: Thursday, January 14, 2010 5:56 PM Subject: Re: Serialization of pointers ? --> loading notworking... replace friend class boost::serialization::access; template <class Archive> void serialize(Archive& ar, const unsigned int version){ ar & this->x & this->y & theta; }
with something like: friend class boost::serialization::access; template <class Archive> void serialize(Archive& ar, const unsigned int version){ ar & boost::serialization::base_object>(*this); }
Look through the documentation and samples on how to serialize derived classes.
Robert Ramey