Declarations of functions

Can someone explain to me why void foo(int a, int b=3,int c) is wrong? and why the correct ones are correct. I don't understand. Thanks!

1
2
3
4
5
6
7
8
9
10
11
Check all correct declarations of functions. 
  
void foo(int a, int b = 3, int c = 6); Correct
    
void foo(int a = 0, int b, int c);
    
void foo(int a, int b = 3, int c); Wrong
 
void foo(int a, int b, int c); Correct
 
void foo(int a, int b = 3, int c = b);
Default parameters start from the right most parameter and once you have a non-default parameter everything to the left can not have a default parameter.

Also using a parameter as a default for another parameter is not allowed.

Topic archived. No new replies allowed.