Convenient C++ struct initialisation

后端 未结 13 790
谎友^
谎友^ 2020-12-07 10:15

I\'m trying to find a convenient way to initialise \'pod\' C++ structs. Now, consider the following struct:

struct FooBar {
  int foo;
  float bar;
};
// jus         


        
13条回答
  •  广开言路
    2020-12-07 10:33

    Since style A is not allowed in C++ and you don't want style B then how about using style BX:

    FooBar fb = { /*.foo=*/ 12, /*.bar=*/ 3.4 };  // :)
    

    At least help at some extent.

提交回复
热议问题