C++ struct初始化

C++ struct初始化

struct初始化

摘自C++ Structure Initialization

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++ Structure Initialization

发布了92 篇原创文章 · 获赞 9 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/keineahnung2345/article/details/104081154