Possible Duplicate:
How to use local classes with templates?
g++ 4.4 is refusing to compile a call to a template function taking a function-local class as a template parameter. Like so:
// Given this:
template <typename C>
int f(const C& c) {
return c.g();
}
// This compiles fine:
struct C1 {
int g() const { return 42; }
};
int h1() {
return f(C1());
}
// But this doesn't:
int h2() {
struct C2 {
int g() const { return 42; }
};
return f(C2()); // error: no matching function for call to "f(h2()::C2)"
}
// Nor does this:
int h3() {
struct C3 {
int g() const { return 42; }
};
return f<C3>(C3()); // same error
}
What gives? How do I make this work? (In the real program from which this is pruned, "h" is a member function, and "C" has to be a nested class so that it's implicitly a friend of the class of which "h" is a member.)