I am creating a custom ostream class which is briefly exposed in the following snippet. I would like to be able to use std::endl
but the compiler does not let me. I don’t understand why.
#include <iostream>
struct Bar
{
};
template <typename T>
struct Foo
{
};
template <typename T, typename U>
Foo<T>& operator<<(Foo<T>& _foo, U&&)
{
return _foo;
}
int main()
{
Foo<Bar> f;
f << "aa" << std::endl;
}
The error gcc 4.7.1 gives me is:
main.cpp:21:21: error: no match for ‘operator<<’ in ‘operator<< ((* & f), (*"aa")) << std::endl’ main.cpp:21:21: note: candidates are: main.cpp:13:9: note: template Foo& operator<<(Foo&, U&&) main.cpp:13:9: note: template argument deduction/substitution failed: main.cpp:21:21: note:
couldn't deduce template parameter ‘U’
Why can’t it deduce parameter U? Shouldn’t this be typeof(std::endl)
?
decltype
andtypeid
for that. – chrisdecltype
. – qdiiinstanceof
? :-) – obataku