Sign in to follow this  

boost serialization to xml has problems

This topic is 3313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In a test Win32 console app, the following code throws a boost exception when run:
#include "stdafx.h"
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <fstream>

class SomeClass
{
public:
	SomeClass() : m_foo(666), m_bar(777.f) {}

private:
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive& archive, const unsigned int version)
	{
		archive & boost::serialization::make_nvp("Foo", m_foo);
		archive & boost::serialization::make_nvp("Bar", m_bar);
	}

	int m_foo;
	float m_bar;
};

int _tmain(int argc, _TCHAR* argv[])
{
	SomeClass someClass;
	std::ofstream fileStream("TestFile.object");
	boost::archive::xml_oarchive oa(fileStream);
	oa << boost::serialization::make_nvp("Some Class", someClass);

	return 0;
}
If I do not use make_nvp, the code doesn't even compile. Switching from xml_oarchive to text_oarchive works without problem. Can someone tell me what I am doing wrong? Thanks

Share this post


Link to post
Share on other sites

This topic is 3313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this