Convenient C++ struct initialisation

后端 未结 13 742
谎友^
谎友^ 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:29

    The way /* B */ is fine in C++ also the C++0x is going to extend the syntax so it is useful for C++ containers too. I do not understand why you call it bad style?

    If you want to indicate parameters with names then you can use boost parameter library, but it may confuse someone unfamiliar with it.

    Reordering struct members is like reordering function parameters, such refactoring may cause problems if you don't do it very carefully.

提交回复
热议问题