This code compiles in CodeGear 2009 and Visual Studio 2010 but not gcc. Why?
class Foo
{
public:
operator int() const;
template <typename T> T get() const { return this->operator T(); }
};
Foo::operator int() const
{
return 5;
}
The error message is:
test.cpp: In member function `T Foo::get() const’:
test.cpp:6: error: ‘const class Foo’ has no member named ‘operator T’
It’s a bug in G++.
operator Tis an unqualified dependent name (because it hasTin it and lookup will thus be different depending on its type). As such it has to be looked up when instantiating. The Standard rulesThus the type name specified after the operator keyword doesn’t have to match lexically in any way. You can apply the following work-around to force GCC treating it as a dependent name