的Visual Studio 2012的错误C2039:'序列化':是不是成员'的std :: shared_ptr的<&_Ty GT;' [英] Visual Studio 2012 error C2039: 'serialize' : is not a member of 'std::shared_ptr<_Ty>'

查看:2735
本文介绍了的Visual Studio 2012的错误C2039:'序列化':是不是成员'的std :: shared_ptr的<&_Ty GT;'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持这个问题,而我编译的静态类库。

我知道,升压不正式支持VS2012但由于这是我目前的开发环境,我真的可以使用一些建议。

我一直在寻找周围,但没有迄今已帮助了我。

样code:

foo.h中:

 的#includeFooImpl.h
#包括LT&;升压/系列化/ serialization.hpp>
#包括LT&;升压/系列化/ shared_ptr.hpp>
#包括LT&;升压/存档/ text_iarchive.hpp>
#包括LT&;升压/存档/ text_oarchive.hpp>Foo类
{
上市:
    美孚(void):在平普尔(性病:: make_shared< FooImpl>()){}
    //类似的构造遵循    //一些get方法在这里
私人的:
    的std :: shared_ptr的< FooImpl>平普尔;    友元类的boost ::系列化::访问;
    模板< typename的归档和GT;
    无效连载(归档和放大器; AR,const的无符号整型FILE_VERSION);
}

Foo.cpp中:

 的#includestdafx.h中
的#includefoo.h中模板<类归档和GT;
无效美孚::连载(归档和放大器; AR,const的无符号整型版)
{
    AR&安培;平普尔;
}模板无效美孚::连载<提高::档案:: text_iarchive>(
    提高::档案:: text_iarchive&安培; AR,
    const的无符号整型FILE_VERSION
);
模板无效美孚::连载<提高::档案:: text_oarchive的>(
    提高::档案:: text_oarchive的&安培; AR,
    const的无符号整型FILE_VERSION
);

FooImpl.h:

 的#include<升压/系列化/ serialization.hpp>
#包括LT&;升压/系列化/ string.hpp>类FooImpl
{
上市:
    FooImpl(无效);
    //其他构造函数,get方法私人的:
    //数据成员 - 无符号整型和放大器;的std :: wstring的    友元类的boost ::系列化::访问;
    模板< typename的归档和GT;
    无效连载(归档和放大器; AR,const的无符号整型版);
};

FooImpl.cpp:

 的#includestdafx.h中
#包括FooImpl.h//函数实现模板< typename的归档和GT;
无效FooImpl ::连载(归档和放大器; AR,const的无符号整型版)
{
    AR&安培; ID_;
    AR&安培; code_;
}//后来添加的,系列化要求这些模板无效FooImpl ::连载<提高::档案:: text_iarchive>(
    提高::档案:: text_iarchive&安培; AR,
    const的无符号整型FILE_VERSION
);模板无效FooImpl ::连载<提高::档案:: text_oarchive的>(
    提高::档案:: text_oarchive的&安培; AR,
    const的无符号整型FILE_VERSION
);


解决方案

您正试图序列化指针。要序列化的东西指针指向。最简单的方法是更换富<< PTR; 富<< (* PTR);

围绕 * PTR 括号是没有必要,很多人会认为他们是笨拙的迹象。但是,如果你发现他们更清楚你,使用它们。

I am stuck with this problem while compiling my static class library.

I know that Boost doesn't officially support VS2012 but since this is my current development environment, I could really use some advice.

I have been searching around but nothing so far has helped me.

Sample code:

Foo.h:

#include "FooImpl.h"
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

class Foo
{
public:
    Foo(void) : pImpl(std::make_shared<FooImpl>()) {}
    //similar constructors follow

    //a few get methods here
private:
    std::shared_ptr<FooImpl> pImpl;

    friend class boost::serialization::access;
    template <typename Archive>
    void serialize(Archive & ar, const unsigned int file_version);
}

Foo.cpp:

#include "stdafx.h"
#include "Foo.h"

template<class Archive>
void Foo::serialize(Archive& ar, const unsigned int ver) 
{  
    ar & pImpl;
}

template void Foo::serialize<boost::archive::text_iarchive>(
    boost::archive::text_iarchive & ar, 
    const unsigned int file_version
);
template void Foo::serialize<boost::archive::text_oarchive>(
    boost::archive::text_oarchive & ar, 
    const unsigned int file_version
);

FooImpl.h:

#include <boost/serialization/serialization.hpp>
#include <boost/serialization/string.hpp>

class FooImpl
{
public:
    FooImpl(void);
    //other constructors, get methods

private:
    //data members - unsigned int & std::wstring

    friend class boost::serialization::access;
    template <typename Archive>
    void serialize(Archive& ar, const unsigned int ver);
};

FooImpl.cpp:

#include "stdafx.h"
#include "FooImpl.h"

//function implementations

template <typename Archive>
void FooImpl::serialize(Archive& ar, const unsigned int ver)
{
    ar & id_;
    ar & code_;
}

//Later added, serialization requires these

template void FooImpl::serialize<boost::archive::text_iarchive>(
    boost::archive::text_iarchive & ar, 
    const unsigned int file_version
);

template void FooImpl::serialize<boost::archive::text_oarchive>(
    boost::archive::text_oarchive & ar, 
    const unsigned int file_version
);

解决方案

You are trying to serialize pointers. You want to serialize the thing the pointer points to. The simplest way is to replace foo << ptr; with foo << (*ptr);.

The parentheses around *ptr are not necessary and many would see them as a sign of clumsiness. But if you find they make things clearer for you, use them.

这篇关于的Visual Studio 2012的错误C2039:'序列化':是不是成员'的std :: shared_ptr的&LT;&_Ty GT;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆