Breyta

Deila með


Compiler warning C5037

'member-function': an out-of-line definition of a member of a class template cannot have default arguments

Remarks

Default arguments aren't allowed on out-of-line definitions of member functions in template classes. The compiler issues a level 3 warning under /permissive, and an error under /permissive-.

This warning was introduced in Visual Studio 2017 version 15.3. Code that compiled without warnings in versions of the compiler before Visual Studio 2017 version 15.3 can now generate C5037. For information on how to disable warnings introduced in a particular compiler version or later, see Compiler warnings by compiler version. You can disable it by using the /wd:5037 compiler option or #pragma warning(disable:5037).

Example

In previous versions of Visual Studio, the following ill-formed code could potentially cause a runtime crash. Visual Studio 2017 version 15.3 produces warning C5037:

// C5037.cpp
// compile using: cl /c /permissive- C5037.cpp
template <typename T>
struct A {
    T f(T t, bool b = false);
};

template <typename T>
T A<T>::f(T t, bool b = false) // C5037: 'A<T>::f': an out-of-line definition of a member of a class template cannot have default arguments
{
    // ...
}

To fix the error, remove the = false default argument.