Cpp cannot provide default arguments in both the function declaration and definition

⌚Time: 2026-02-07 18:09:00

👨‍💻Author: Jack Ge

This is a compiler error.

error: default argument given for parameter 5 of 'bool get_files
_and_folders_name_list_end_with_slash(const string&, std::vector<std::__cxx11::basic_stri
ng<char> >&, std::vector<std::__cxx11::basic_string<char> >&, bool, bool)' [-fpermissive]

                                                    bool include_system = false) 

The reason is that I included default parameter values both in the function header declaration and the source file definition.

For example,

//header:
void function(int a = 3);

//cpp:
void function(int a = 3){
    ...
}

The default value should only be set in one place.

//header:
void function(int a = 3);

//cpp:
void function(int a){
    ...
}