首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

TGridRect对象怎么方便地初始化

2013-09-18 
TGridRect对象如何方便地初始化声明如下:struct DECLSPEC_DRECORD TGridRect{#pragma pack(push,1)union{s

TGridRect对象如何方便地初始化
声明如下:

struct DECLSPEC_DRECORD TGridRect
{
#pragma pack(push,1)
union
{
struct 
{
TGridCoord TopLeft;
TGridCoord BottomRight;
};
struct 
{
int Left;
int Top;
int Right;
int Bottom;
};

};
#pragma pack(pop)
};

这种union和struct嵌套的怪胎如何像普通struct一样用[struct名](成员1,成员2, ...)的形式声明一个对象并初始化呢?
要不然只能用[struct名].[成员名1]=...这种形式了,好麻烦。
struct union 声明
[解决办法]
TGridRect gr = { { 100, 200 }, { 300, 400 } };

那么,Left = 100, Top = 200, Right = 300, Bottom = 400

热点排行