地图中的结构 [英] struct in map

查看:58
本文介绍了地图中的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想做这样的事情:


typedef struct {

unsigned短信息;

int SeqNr;

} MsgStruct;

map< string,MsgStructMyMsg;


现在我想知道这是如何与标准兼容的,以及我将如何直接访问结构变量?

会是这样的:

MyMsg [" index"]。msg = 0xabcd;?

我不是百分百确定这是否可行并且我没有编译器方便

现在来测试一下。


感谢您的意见,

Ron

-

周软件工程安全时间计划;)

Hi,

I would like to do something like this:

typedef struct{
unsigned short msg;
int SeqNr;
} MsgStruct;
map <string, MsgStructMyMsg;

Now I''m wondering how this is compatible with the standard and how I would
access the structs variables directly?
Would it be something like this:
MyMsg["index"].msg= 0xabcd;?
I''m not 100% sure if this would work and i don''t have a compiler handy right
now to test this.

Thanks for your opinion,
Ron
--
weeks of software enineering safe hours of planing ;)

推荐答案

Ron Eggler写道:
Ron Eggler wrote:




我想做这样的事情:


typedef struct {

unsigned short msg;

int SeqNr;

} MsgStruct;
Hi,

I would like to do something like this:

typedef struct{
unsigned short msg;
int SeqNr;
} MsgStruct;



请考虑放弃这个C-ism。在C ++中我们只需编写


struct MsgStruct {

unsigned short msg;

int SeqNr;

};

Please consider abandoning this C-ism. In C++ we simply write

struct MsgStruct {
unsigned short msg;
int SeqNr;
};


map< string,MsgStructMyMsg;


现在我想知道这是如何兼容的标准以及如何直接访问结构变量?

map <string, MsgStructMyMsg;

Now I''m wondering how this is compatible with the standard and how I would
access the structs variables directly?



兼容。存储项目的要求相对宽松,并且支持像您的结构一样的POD。项目

需要是可分配和可复制的。 POD是。

It is compatible. The requirements for the stored items are relatively
relaxed and such that PODs like your struct are supported. The items
need to be Assignable and Copyconstructible. PODs are.


会是这样的:

MyMsg [" index"]。msg = 0xabcd;?
Would it be something like this:
MyMsg["index"].msg= 0xabcd;?



这应该有效。

That should work.


我不是百分百肯定这是否有用而我没有一个方便的编译器

现在测试一下。
I''m not 100% sure if this would work and i don''t have a compiler handy right
now to test this.



地图的索引返回对存储结构的引用。

在该引用上使用成员访问运算符是完全可以的,并且

也允许通过赋值操作更改成员。没问题

AFAICS。


V

-

请删除大写''A'在回复电子邮件时

我没有回复最热门的回复,请不要问

The indexing of your map returns a reference to the stored struct.
Using the member access operator on that reference is perfectly OK, and
changing the member via the assignment op is allowed too. No problem
AFAICS.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask



" Ron Eggler" < un ***** @example.comaécritdansle message de news:

K4X%j.3

"Ron Eggler" <un*****@example.coma écrit dans le message de news:
K4X%j.3


Gn.1@edtnps92 .. 。
Gn.1@edtnps92...




我想做这样的事情:


typedef struct {

unsigned short msg;

int SeqNr;

} MsgStruct;

map< string,MsgStructMyMsg;


现在我想知道这是如何与标准兼容的,以及我将如何直接访问结构变量?

它会是这样的:

MyMsg [" index"]。msg = 0xabcd;?

我不是100%肯定是否这会工作,我没有编译器方便

正确

现在测试这个。
Hi,

I would like to do something like this:

typedef struct{
unsigned short msg;
int SeqNr;
} MsgStruct;
map <string, MsgStructMyMsg;

Now I''m wondering how this is compatible with the standard and how I would
access the structs variables directly?
Would it be something like this:
MyMsg["index"].msg= 0xabcd;?
I''m not 100% sure if this would work and i don''t have a compiler handy
right
now to test this.



您可以随时使用像这样的在线编译器
http://www.comeaucomputing.com/tryitout/

来测试你的代码。

You could always use an online compiler like this one
http://www.comeaucomputing.com/tryitout/
to test your code.


这篇关于地图中的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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