In the example below I print a vector of integers (operator<<
inside main
). I have provided two implementations of the operator. I would like to understand why the first one matches and the second does not. How could I make the second one match?
#include <iostream>
#include <vector>
template< typename value_type, typename allocator_type >
std::ostream& operator<< (
std::ostream& os,
std::vector< value_type, allocator_type >const& v
)
{
os << "[vector-1]" << std::endl;
return os;
}
template< typename VECTOR >
std::ostream& operator<< (
std::ostream& os,
std::vector< typename VECTOR::value_type, typename VECTOR::allocator_type >const& v
)
{
os << "[vector-2]" << std::endl;
return os;
}
int main() {
std::vector v = {1, 2, 3, 4};
std::cerr << v;
}