1
template<typename T>
class MultidimArray:
{
public:
    T* data;
    long int xinit;
    ...
private:
    friend class boost::serialization::access;
    template <class Archive>
        void serialize(Archive &ar, const unsigned int version){
            ar & data;
            ar & xinit;
            ar & ...;
    }
};


stringstream ss; 
void serializateWs(){
    MultidimArray<DOUBLE> Mpack;
    boost::archive::text_oarchive oa(ss);
    oa << Mpack;
}

Compile error: request for member ‘serialize’ in ‘t’, which is of non-class type ‘double’. But it will be fine without "T * data". I found an answer How to serialize derived template classes with Boost.serialize? I add this line "oa.template register_type< MultidimArray >();". But I got this " error| ‘template’ (as a disambiguator) is only allowed within templates" when compiling. How can I serialize and deserialize this kind of class?

Community
  • 1
  • 1
Raloy
  • 11
  • 3

1 Answers1

0

Use the array wrapper: http://www.boost.org/doc/libs/1_49_0/libs/serialization/doc/wrappers.html#arrays, e.g. like:

ar & boost::serialization::make_array(data, xinit)
   & ...;

Registering types has nothing to with things, unless T is a polymorphic pointer.

sehe
  • 374,641
  • 47
  • 450
  • 633