Skip Navigation

structs with designated initializers as named function parameters

Recently I end up using structs everywhere as functions parameters to basically get named function parameters and better default arguments. Are there any downsides to this? So far the only annoying thing is to have to define those structs.

struct FunParams{
    int i = 5;
    float f = 3.14f;
    std::string s = "hello";
};

void Fun(const FunParams& params){}

int main(){
    Fun({.s = "hi there"});
}
6

You're viewing a single thread.

6 comments
6 comments