Skip to content

Improve C2548 #4964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions docs/error-messages/compiler-errors-2/compiler-error-c2548.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
---
description: "Learn more about: Compiler Error C2548"
title: "Compiler Error C2548"
ms.date: "11/04/2016"
ms.date: "03/01/2024"
f1_keywords: ["C2548"]
helpviewer_keywords: ["C2548"]
ms.assetid: 01e9c835-9bf3-4020-9295-5ee448c519f3
---
# Compiler Error C2548

'class::member' : missing default parameter for parameter parameter

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.
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.

## Example

The following sample generates C2548:
The following sample generates C2548 for:

- `func1` because it's missing the default argument `b`
- `func3` because it's missing the default argument `c`.

The following sample doesn't generate C2548 for:

- `func2` because all the required default arguments are supplied.
- The second `func4` declaration because the default argument `c` is supplied in the preceding declaration and is in the same scope.
- The third `func4` declaration because both default arguments `b` and `c` are provided previously.

```cpp
// C2548.cpp
// compile with: /c
void func( int = 1, int, int = 3); // C2548
void func1(int a = 1, int b, int c = 3); // C2548

void func2(int a = 1, int b = 2, int c = 3); // OK

void func3(int a, int b = 2, int c); // C2548

// OK
void func2( int, int, int = 3);
void func3( int, int = 2, int = 3);
void func4(int a, int b, int c = 3); // OK
void func4(int a, int b = 2, int c); // OK
void func4(int a = 1, int b, int c); // OK
```