79699293

Date: 2025-07-12 13:01:25
Score: 0.5
Natty:
Report link

When defining a member function of a class template outside the class definition, the rules for template parameter repetition depend on the context:

  1. Before :: (Qualified Name)

You must repeat the template parameters because you're specifying the full type of the class template:

template<std::signed_integral T>
Ratio<T>& Ratio<T>::operator+=(...) { ... }
//      ^^^^^^^^ Required: `Ratio<T>`
  1. Return Type

You must repeat the template parameters because the return type is outside the scope of the class:

template<std::signed_integral T>
Ratio<T>& Ratio<T>::operator+=(...) { ... }
// ^^^^^^^ Required: `Ratio<T>&`
  1. Function Parameters

You do not need to repeat them because:

template<std::signed_integral T>
Ratio<T>& Ratio<T>::operator+=(const Ratio& R) { ... }
//                              ^^^^^^ No `<T>` needed here

And why this happen ?

template<std::signed_integral T>
struct Ratio {
    Ratio& operator+=(const Ratio& R); // `Ratio` = `Ratio<T>`
};
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): When
  • Low reputation (1):
Posted by: Mohamed Wael