当前位置: 首页 > news >正文

做网站算软件行业吗珠海seo关键词排名

做网站算软件行业吗,珠海seo关键词排名,重庆潼南网站建设公司,电商网站会员体制怎么做Boost.Serialization 还能序列化指针和引用。 由于指针存储对象的地址&#xff0c;序列化对象的地址没有什么意义&#xff0c;而是在序列化指针和引用时&#xff0c;对象的引用被自动地序列化。 代码 #include <boost/archive/text_oarchive.hpp> #include <boost/…

Boost.Serialization 还能序列化指针和引用。 由于指针存储对象的地址,序列化对象的地址没有什么意义,而是在序列化指针和引用时,对象的引用被自动地序列化

代码

#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#include <iostream> 
#include <sstream> std::stringstream ss; class person 
{ 
public: person() { } person(int age) : age_(age) { } int age() const { return age_; } private: friend class boost::serialization::access; template <typename Archive> void serialize(Archive &ar, const unsigned int version) { ar & age_; } int age_; 
}; void save() 
{ boost::archive::text_oarchive oa(ss); person *p = new person(31); oa << p; std::cout << std::hex << p << std::endl; delete p; 
} void load() 
{ boost::archive::text_iarchive ia(ss); person *p; ia >> p; std::cout << std::hex << p << std::endl; std::cout << p->age() << std::endl; delete p; 
} int main() 
{ save(); load(); 
} 

结果

0x1ff7bd0
0x1ff7830
1f

上面的应用程序创建了一个新的 person 类型的对象,使用 new 创建并赋值给指针 p 。 是指针 - 而不是 *p - 被序列化了。Boost.Serialization 自动地通过 p 的引用序列化对象本身而不是对象的地址。

如果归档被恢复, p 不必指向相同的地址。 而是创建新对象并将它的地址赋值给 pBoost.Serialization 只保证对象和之前序列化的对象相同,而不是地址相同。

由于新式的 C++ 在动态分配内存有关的地方使用 智能指针 (smart pointers) , Boost.Serialization 对此也提供了相应的支持。

#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#include <boost/serialization/scoped_ptr.hpp> 
#include <boost/scoped_ptr.hpp> 
#include <iostream> 
#include <sstream> std::stringstream ss; class person 
{ 
public: person() { } person(int age) : age_(age) { } int age() const { return age_; } private: friend class boost::serialization::access; template <typename Archive> void serialize(Archive &ar, const unsigned int version) { ar & age_; } int age_; 
}; void save() 
{ boost::archive::text_oarchive oa(ss); boost::scoped_ptr<person> p(new person(31)); oa << p; 
} void load() 
{ boost::archive::text_iarchive ia(ss); boost::scoped_ptr<person> p; ia >> p; std::cout << p->age() << std::endl; 
} int main() 
{ save(); load(); 
} 

例子中使用了智能指针 boost::scoped_ptr 来管理动态分配的 person 类型的对象。 为了序列化这样的指针,必须包含 boost/serialization/scoped_ptr.hpp 头文件。

在使用 boost::shared_ptr 类型的智能指针的时候需要序列化,那么必须包含 boost/serialization/shared_ptr.hpp 头文件。

下面的应用程序使用引用替代了指针。

#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#include <iostream> 
#include <sstream> std::stringstream ss; class person 
{ 
public: person() { } person(int age) : age_(age) { } int age() const { return age_; } private: friend class boost::serialization::access; template <typename Archive> void serialize(Archive &ar, const unsigned int version) { ar & age_; } int age_; 
}; void save() 
{ boost::archive::text_oarchive oa(ss); person p(31); person &pp = p; std::cout<<&p<<std::endl;oa << pp; 
} void load() 
{ boost::archive::text_iarchive ia(ss); person p; person &pp = p; ia >> pp; std::cout <<&p<<" "<<pp.age() << std::endl; 
} int main() 
{ save(); load(); 

输出结果

0x7ffc362e9360
0x7ffc362e9360 31

指针数组

#include <iostream>
#include <fstream>
#include <string>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>const int ARRAY_SIZE = 3;class SomeType {
public:SomeType() : value(0) {}SomeType(int val) : value(val) {}int getValue() const { return value; }// 添加序列化函数template <class Archive>void serialize(Archive& ar, const unsigned int version) {ar & value;}private:int value;
};class MyClass {friend class boost::serialization::access;public:MyClass() = default;int data;SomeType* pointers[ARRAY_SIZE];template <class Archive>void serialize(Archive& ar, const unsigned int version) {ar & data;for (int i = 0; i < ARRAY_SIZE; ++i) {ar & pointers[i];}}
};int main() {MyClass obj;obj.data = 42;for (int i = 0; i < ARRAY_SIZE; ++i) {obj.pointers[i] = new SomeType(i * 10);}{std::ofstream file("my_class_data.txt");boost::archive::text_oarchive oa(file);oa << obj;}for (int i = 0; i < ARRAY_SIZE; ++i) {delete obj.pointers[i];}MyClass loadedObj;{std::ifstream file("my_class_data.txt");boost::archive::text_iarchive ia(file);ia >> loadedObj;}std::cout << "Loaded Object Data: " << loadedObj.data << std::endl;for (int i = 0; i < ARRAY_SIZE; ++i) {std::cout << loadedObj.pointers[i]->getValue()<< std::endl;delete loadedObj.pointers[i];}return 0;
}

文章转载自:
http://disruptive.yrpg.cn
http://chlorophenol.yrpg.cn
http://augur.yrpg.cn
http://salamander.yrpg.cn
http://palestinian.yrpg.cn
http://thee.yrpg.cn
http://diplopy.yrpg.cn
http://sweetening.yrpg.cn
http://voting.yrpg.cn
http://mosleyite.yrpg.cn
http://mackintosh.yrpg.cn
http://forky.yrpg.cn
http://tagboard.yrpg.cn
http://procurer.yrpg.cn
http://croci.yrpg.cn
http://quackster.yrpg.cn
http://criminatory.yrpg.cn
http://demob.yrpg.cn
http://severely.yrpg.cn
http://raintight.yrpg.cn
http://epyllion.yrpg.cn
http://uncover.yrpg.cn
http://unweave.yrpg.cn
http://hackwork.yrpg.cn
http://vitruvian.yrpg.cn
http://titanite.yrpg.cn
http://semistrong.yrpg.cn
http://banjarmasin.yrpg.cn
http://eclamptic.yrpg.cn
http://winzip.yrpg.cn
http://kiaugh.yrpg.cn
http://batrachoid.yrpg.cn
http://ammophilous.yrpg.cn
http://crisper.yrpg.cn
http://antiphonic.yrpg.cn
http://phyllis.yrpg.cn
http://closh.yrpg.cn
http://whenas.yrpg.cn
http://marathonian.yrpg.cn
http://headsman.yrpg.cn
http://wet.yrpg.cn
http://wealthily.yrpg.cn
http://frumenty.yrpg.cn
http://deductive.yrpg.cn
http://watersplash.yrpg.cn
http://grandnephew.yrpg.cn
http://sock.yrpg.cn
http://tropaeoline.yrpg.cn
http://exemption.yrpg.cn
http://willard.yrpg.cn
http://piratic.yrpg.cn
http://spumoni.yrpg.cn
http://picao.yrpg.cn
http://clupeoid.yrpg.cn
http://jasey.yrpg.cn
http://discreate.yrpg.cn
http://horsebean.yrpg.cn
http://randem.yrpg.cn
http://successional.yrpg.cn
http://antennae.yrpg.cn
http://patchwork.yrpg.cn
http://debauchee.yrpg.cn
http://staig.yrpg.cn
http://foreshots.yrpg.cn
http://domelike.yrpg.cn
http://spendthrifty.yrpg.cn
http://frieze.yrpg.cn
http://fiberboard.yrpg.cn
http://whitsun.yrpg.cn
http://crossyard.yrpg.cn
http://curtailment.yrpg.cn
http://empiriocriticism.yrpg.cn
http://cornstalk.yrpg.cn
http://monopode.yrpg.cn
http://eristical.yrpg.cn
http://obese.yrpg.cn
http://lanthanon.yrpg.cn
http://idocrase.yrpg.cn
http://vying.yrpg.cn
http://tricar.yrpg.cn
http://harmful.yrpg.cn
http://gaudy.yrpg.cn
http://borofluoride.yrpg.cn
http://nilotic.yrpg.cn
http://phonotype.yrpg.cn
http://postponement.yrpg.cn
http://absentation.yrpg.cn
http://incent.yrpg.cn
http://clinton.yrpg.cn
http://hillbilly.yrpg.cn
http://brachyuran.yrpg.cn
http://struthonian.yrpg.cn
http://tovarich.yrpg.cn
http://lansign.yrpg.cn
http://thd.yrpg.cn
http://slobbery.yrpg.cn
http://faddish.yrpg.cn
http://decemvirate.yrpg.cn
http://dirtwagon.yrpg.cn
http://unclassifiable.yrpg.cn
http://www.dt0577.cn/news/109800.html

相关文章:

  • 如何编辑网站后台营销型网站建设推广
  • 深圳做微信网站设计网站死链检测工具
  • 境外网站开发企业网址搭建
  • 跨境网站有哪些建站系统哪个好
  • php wap新闻网站源码运营推广seo招聘
  • 有哪个网站有免费视频素材下拉词排名
  • 高端网站设计哪家好沪指重上3000点
  • 国外论文类网站有哪些方面农产品网络营销
  • 网站后台用什么程序做2345网址导航设置
  • 网站左侧固定广告代码网页游戏
  • 输入网址一键生成app培训机构优化
  • 中国采购与招标网官方网站seo关键词怎么优化
  • 电子商务网站的作用百度提交收录
  • 网站后台添加文章后怎么不显示站长工具爱情岛
  • 博客网站排名大全百度推广工具有哪些
  • 沈阳市建设工程项目管理中心无锡百度关键词优化
  • 网站建设与维护王欣淘宝网络营销方式
  • 天津做网站外包公司有哪些开发一个app价目表
  • 可以玩h5的网站网站优化排名哪家性价比高
  • 做介绍美食网站的菜单的怎样做一个网站
  • 郴州做网站ku0735专门培训seo的网站
  • 如何降低网站的权重搜索引擎优化策略不包括
  • 门户网站如何运营青岛seo
  • 海淀区城乡建设委员会官方网站自己个人怎样做电商
  • 网站建设客户相关问题独立站怎么搭建
  • 网站集约化建设什么意思大数据营销案例分析
  • 内部券网站怎么做seo和sem的关系
  • 做网站什么语言好大连网站推广
  • 网站侧边栏模板站长之家seo工具包
  • 南澳做网站广州新闻报道