Why won't the commented-line in goo
compile? Instead I have to resort to defining the global function hoo
instead of using the Thing
member function foo
?
#include <iostream>
template <typename... T>
struct Thing {
template <typename U> void foo() {std::cout << this << '\n';}
};
template <typename U, typename... T>
void hoo (const Thing<T...>& thing) {std::cout << &thing << '\n';}
template <typename U, typename... T>
void goo (const Thing<T...>& thing) {
// thing.foo<U>(); // Why won't this line compile?
hoo<U>(thing); // Using this instead.
}
int main() {
Thing<int, double, char> thing;
goo<short>(thing);
}
What is the change that is needed so that I can use foo() instead?