Explicit operator << selects "incorrect" overload
I play with variable templates and wrote this based on this answer :
template <size_t... I>
void print(seq<I...>)
{
decltype(std::cout) * dummy[sizeof...(I)] = { &(std::cout << I << ' ')... };
}
Since it std::cout::operator<<
has a return type, it can be saved, so there is no need for a trick ( ,0)
.
Now, to close the warning "unused variable 'dummy'" and print a new line, I tried the following instructions, but they did not do what I wanted:
dummy[0]->operator <<('\n'); // prints 10
(apparently called operator<<(int)
insteadoperator<<(char)
dummy[0]->operator <<("\n"); // prints a pointer
(apparently called operator<<(const void*)
insteadoperator<<(const char*)
In the end, I had to write
*dummy[0] << '\n'; // prints a newline as desired
My question is: why were the "wrong" overloads chosen?