i'm trying to implement a simple template array class, but when i came into the operator< i actually have to use a template :
my code is something like :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
template<typename _Type, std::size_t _Size>
class array {
public :
// ... bla bla bla
template<typename _Type, std::size_t _Size>
booloperator< ( const array<_Type, _Size>& _first,
const array<_Type, _Size>& _second ) {
return std::lexicographical_compare( _first.begin(), _first.end() ... )
}
private :
_Type value_[ _Size ];
};
but i am having an error of shadows template param 'class _Type'
is it w/ the name conflict between the array template parameter and the function template parameter ?
Yes, you can't shadow template parameters. Just give them different names (both _Type and _Size) and you're good to go.
Also, I think you meant to make that a friend declaration. If that's the case, you don't need to template it - it can be automatically templated just by being defined inside the template class.
but i've actually looked at the C++ header <array> and the template class parameter and the template function parameter names are actually same, why is that ?
Are you sure? Can you link to the source file in question and give line numbers? (Depending on your compiler, it's most certainly available online in your browser, no need to paste code)
> but i've actually looked at the C++ header <array> and the template class parameter
> and the template function parameter names are actually same, why is that ?
std::array<> does not have any member templates.
The templated functions in the header (comparison operators, get and swap) are non-member functions.