初始化结构数组 [英] Initializing an array of structure

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

问题描述

我需要创建 组列表和每个组将具有不同数量的任务。

I need to create  list of Groups and each group will have different number of tasks.

CString Groups [16];

CString Groups[16];

struct tasks

struct tasks

{

CString strTaskName;

CString strTaskName;

int nCmdId;

int nCmdId;

};

struct

{

CString Groupnmae;

CString Groupnmae;

结构任务列表 

list of struct tasks 

};

是否可以为此方案创建静态数组?

Is it possible to create static array for this scenario?

如何初始化此方法数组?

How to initialize this array?

推荐答案

也许是这样的:

Maybe like this:

struct Task
{
   CString taskName;
   int cmdId;
};

struct Group
{
   CString groupName;
   std::vector<Task> tasks;
};

Group groups[] =
{
   { L"group 1", { {L"task 1", 10}, {L"task 2", 20} } },
   { L"group 2", { {L"task 3", 30} } }
};




在简单编码的情况下删除"L"。


Remove 'L' in case of simple encoding.


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

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