Can I set a default argument from a previous argument?

后端 未结 7 1771
终归单人心
终归单人心 2020-11-27 20:09

Is it possible to use previous arguments in a functions parameter list as the default value for later arguments in the parameter list? For instance,

void f(         


        
7条回答
  •  时光取名叫无心
    2020-11-27 20:32

    The answer is no, you can't. You could get the behaviour you want using overloads:

    void f(int a, int b, int c);
    inline void f(int a, int b) { f(a,b,b); }
    inline void f(int a)        { f(a,a,a); }
    

    As for the last question, C doesn't allow default parameters at all.

提交回复
热议问题