Let's say I have the following snippet:
template <class T> void f(T arg) { arg(); }
void g()
{
struct { void operator()(void) { } } foo;
f(foo);
}
Visual C++ accepts this. However, when I try GCC, I get:
$ g++ --version # just in case this matters
g++ (Debian 4.4.5-8) 4.4.5
...
$ g++ foo.cc
foo.cc: In function 'void g()':
foo.cc:7: error: no matching function for call to 'f(g()::<anonymous struct>&)'
When foo
is scoped globally and its type has a name, this works. But when the type is anonymous or declared inside g()
it does not.
Why does GCC reject this? Is it valid C++?