C++ struct初始化
发布日期:2021-05-06 19:47:43 浏览次数:22 分类:技术文章

本文共 933 字,大约阅读时间需要 3 分钟。

C++ struct初始化

struct初始化

摘自:

The field identifiers are indeed C initializer syntax. In C++ just give the values in the correct order without the field names. Unfortunately this means you need to give them all (actually you can omit trailing zero-valued fields and the result will be the same).

在C++中初始化struct不需要寫出各field的名字,只需要確保各值的順序與field在struct中的順序一致就行。

getopt.h中定義了struct option

struct option {
const char *name; int has_arg; int *flag; int val;};

TensorRT/samples/common/argsParser.h中,對struct option型別的變數進行初始化:

static struct option long_options[] = {
{
"help", no_argument, 0, 'h'}, {
"datadir", required_argument, 0, 'd'}, {
"int8", no_argument, 0, 'i'}, {
"fp16", no_argument, 0, 'f'}, {
"useILoop", no_argument, 0, 'l'}, {
"useDLACore", required_argument, 0, 'u'}, {
"batch", required_argument, 0, 'b'}, {
nullptr, 0, nullptr, 0}};

參考連結

上一篇:C++ typedef struct v.s. struct
下一篇:C getopt.h

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年03月30日 10时25分55秒