|
1 | 1 | ---
|
2 | 2 | description: "Learn more about: Compiler Error C2548"
|
3 |
| -title: "Compiler Error C2548" |
4 |
| -ms.date: "11/04/2016" |
| 3 | +title: "Compiler error C2548" |
| 4 | +ms.date: "03/01/2024" |
5 | 5 | f1_keywords: ["C2548"]
|
6 | 6 | helpviewer_keywords: ["C2548"]
|
7 |
| -ms.assetid: 01e9c835-9bf3-4020-9295-5ee448c519f3 |
8 | 7 | ---
|
9 |
| -# Compiler Error C2548 |
| 8 | +# Compiler error C2548 |
10 | 9 |
|
11 | 10 | 'class::member' : missing default parameter for parameter parameter
|
12 | 11 |
|
13 |
| -The default parameter list is missing a parameter. If you supply a default parameter anywhere in a parameter list, you must define default parameters for all subsequent parameters. |
| 12 | +The default parameter list is missing a parameter. If you supply a default parameter anywhere in a parameter list, you must define default parameters for all subsequent parameters in the current declaration or any previous declarations within the same scope. |
14 | 13 |
|
15 | 14 | ## Example
|
16 | 15 |
|
17 |
| -The following sample generates C2548: |
| 16 | +The following sample generates C2548 for: |
| 17 | + |
| 18 | +- `func1` because it's missing the default argument `b`. |
| 19 | +- `func3` because it's missing the default argument `c`. |
| 20 | + |
| 21 | +The following sample doesn't generate C2548 for: |
| 22 | + |
| 23 | +- `func2` because all the required default arguments are supplied. |
| 24 | +- The second `func4` declaration because the default argument `c` is supplied in the preceding declaration and is in the same scope. |
| 25 | +- The third `func4` declaration because both default arguments `b` and `c` are provided previously. |
18 | 26 |
|
19 | 27 | ```cpp
|
20 | 28 | // C2548.cpp
|
21 | 29 | // compile with: /c
|
22 |
| -void func( int = 1, int, int = 3); // C2548 |
| 30 | +void func1(int a = 1, int b, int c = 3); // C2548 |
| 31 | + |
| 32 | +void func2(int a = 1, int b = 2, int c = 3); // OK |
| 33 | + |
| 34 | +void func3(int a, int b = 2, int c); // C2548 |
23 | 35 |
|
24 |
| -// OK |
25 |
| -void func2( int, int, int = 3); |
26 |
| -void func3( int, int = 2, int = 3); |
| 36 | +void func4(int a, int b, int c = 3); // OK |
| 37 | +void func4(int a, int b = 2, int c); // OK |
| 38 | +void func4(int a = 1, int b, int c); // OK |
27 | 39 | ```
|
0 commit comments