Coding⏱️ 3 min read📅 2026-06-04

How to Fix: error: default argument given for parameter 1

Default argument given for parameter 1 in C++ class constructor.

Quick Answer: Move default argument to a separate function or use an initializer list.

The error 'default argument given for parameter 1' occurs in C++ when a function is defined with a default argument value for its parameters, but one of those parameters is used as the first parameter.

This issue can affect any programmer who uses functions with default arguments and has not properly initialized the parameters.

⚠️ Common Causes

  • The primary reason for this error is that C++ does not allow default arguments to be given for the first parameter of a function. This is due to the way in which C++ handles function overloading and the scoping rules.
  • An alternative reason could be if there are multiple parameters with default values, but they are not all at the beginning of the parameter list.

✅ Best Solutions to Fix It

Fixing the issue by reordering parameters

  1. Step 1: Move the first parameter to the end of the function definition, so it is no longer the first parameter.
  2. Step 2: Update any code that calls this function to pass the required value as a separate argument, rather than using a default value.

Avoiding the issue by redefining the class

  1. Step 1: Consider redefining the class to use a different constructor or initialization method.
  2. Step 2: Use an initializer list instead of a constructor to initialize member variables, which can avoid this problem altogether.

✨ Wrapping Up

By following these steps and understanding the root causes of the error, you should be able to resolve the issue and ensure that your code functions correctly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions