Default Arguments Should Not Be Repeatedly Specified in the Function Template Definition
Error Information
1 2 3 4 5 6 | template <typename T = int> void printSize(void); template <typename T = int> void printSize(void) { std::cout << sizeof(T) << std::endl; } |
1 2 3 4 5 6 | error: template parameter redefines default argument 3 | template <typename T = int> | ^ note: previous default template argument defined here 1 | template <typename T = int> | ^ |
Problem
If default arguments have been specified during the declaration of a template function, they should not be repeatedly specified during the definition of the template function.
Solution
- Remove redundant argument specifications.
- Use the clang-tidy tool to identify such issues and provide modification suggestions.
Parent topic: Other Compatibility Problems