I am following this example to serialize an object with boost.

However, I keep getting the same compile error: error C2248: 'boost::scoped_ptr<T>::scoped_ptr' : cannot access private member declared in class 'boost::scoped_ptr<T>'

Any idea why?

// Console2.cpp : Defines the entry point for the console application.

#pragma once
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <fstream>

// include headers that implement a archive in simple text format
#include <boost/regex.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/vector.hpp>

using namespace std;

class MovAvgData
{
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & VCMA;
		ar & PMA;
		ar & PVCMA;
	}
	double VCMA;
	double PVCMA;
	double PMA;
protected:
	MovAvgData(const double vc,const double pvc, const double p):
		 VCMA(vc),
			 PVCMA(pvc),
			 PMA(p)
		 {}
public:
	MovAvgData(){}
	virtual ~MovAvgData(){}
};

class MASummary : public MovAvgData
{
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		// serialize base class information
		ar & boost::serialization::base_object<MovAvgData>(*this);
		ar & PminusPVC;
	}
	double PminusPVC;
public:
	MASummary(){}
	MASummary(const double vc, const double pvc, 
		const double p, const double pmp):
	MovAvgData(vc,pvc,p),
		PminusPVC(pmp)
	{}
};

class GroupVals
{
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive ar, const unsigned int version)
	{
		ar & ma;
	}
public:
	GroupVals(){}
	std::map<std::string, std::vector<MASummary>> ma;
};
int _tmain(int argc, _TCHAR* argv[])
{
	vector<MASummary> ma;
	ma.push_back(MASummary(1,2,3,2));
	GroupVals gp;
	gp.ma[string("test")] = ma;

	// create and open a character archive for output
	std::ofstream ofs("C:\\Users\\J\\Documents\\notes\\serialtest.dat");

	// save data to archive
	{
		boost::archive::text_oarchive oa(ofs);
		// write class instance to archive
		oa << gp;
		// archive and stream closed when destructors are called
	}

	// ... some time later restore the class instance to its original state
	{
		GroupVals gp;
		// create and open an archive for input
		std::ifstream ifs("C:\\Users\\J\\Documents\\notes\\serialtest.dat");
		boost::archive::text_iarchive ia(ifs);
		// read class state from archive
		ia >> gp;
		// archive and stream closed when destructors are called
	}
	cin.get();
	return 0;
}

I've reduced the classes to just two classes and yet I'm still getting the same error. I must be missing something b/c I'm able to get the example to work. As far as I can tell my classes are entirely analogous to the example, but I get a compile error.

class MovAvgData
{
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & VCMA;
	}
	double VCMA;
public:
	MovAvgData(const double vc):
		 VCMA(vc)
		 {}
	MovAvgData(){}
	~MovAvgData(){}
};

class GroupVals
{
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive ar, const unsigned int version)
	{
		ar & ma;
	}
	
public:
	MovAvgData ma;
	GroupVals(){}
	GroupVals(MovAvgData ma):
	ma(ma){}
};


int _tmain(int argc, _TCHAR* argv[])
{
	MovAvgData ma(2);
	const GroupVals gp(ma);

	// create and open a character archive for output
	std::ofstream ofs("C:\\Users\\J\\Documents\\notes\\serialtest.dat");

	// save data to archive
	{
		boost::archive::text_oarchive oa(ofs);
		// write class instance to archive
		oa << gp;
		// archive and stream closed when destructors are called
	}
        return 0;
}

I believe you are missing an ampersand there ...

...
void serialize(Archive & ar, const unsigned int version)
...
Comments
oh my goodness! That's it! Thank you!
well spotted!
This question has already been answered. Start a new discussion instead.