【发布时间】:2014-06-08 03:51:10
【问题描述】:
我是第一次尝试 boost lib,但不知道如何分配字符串映射和共享指针。 这是我的代码,我正在尝试分配价值,但无法做到。
#include <boost\shared_ptr.hpp>
#include <boost\assign.hpp>
#include <boost\map.hpp>
struct X
{
public:
int p;
double q;
X();
~X();
};
struct Y
{
float m;
double n;
Y();
~Y();
};
struct Z
{
public:
std::map<std::string,boost::shared_ptr<X>> Xtype;
std::map<std::string,boost::shared_ptr<Y>> Ytype;
int i;
string name;
Z();
~Z();
};
struct X *x1;
struct Y *y1;
void setx()
{
x1->p=10;
x1->q=20.20;
}
void sety()
{
y1->m=10;
y1->n=20.20;
};
void initialize(Z *z1)
{
z1->i=30;
// how to i add x1 and y1 to Xtype and Ytype respectively of z1 struct
}
我的问题:- 我如何将 x1 和 y1 值分配给 z1 类型的 Xtype 和 Ytype。 真的不知道该怎么做,怎么下手。如果我能够分配,那么我可以继续对其进行序列化。
【问题讨论】:
-
嗨。你似乎很困惑。你知道
std::map是什么以及它是如何工作的吗?shared_ptr呢? -
@manu u hv to spk englsh n ths sit。不是因为我们无法理解事情,而是因为这让你看起来不尊重你想帮助你的人。如果您懒得打几个字,那您根本不会成功,帮助您是浪费时间。
-
对不起先生!我不是故意的..有时很着急..
标签: c++ serialization boost boost-serialization