Reputation: 9028
Should the following code compile in C++98/03?
struct Base
{
template <typename T> void func () { }
void norm() { }
};
struct Derived : public Base { };
template <typename U>
struct Usage
{
typedef void (U::*Method)();
Usage(Method test) { }
};
int main()
{
Usage<Derived> good(&Derived::norm);
// "Error: Cannot use void(*)() to initialize Usage<Derived>." on next line
Usage<Derived> bad(&Derived::func<int>);
return 0;
}
This code snippet worked just fine on nearly every compiler that I was able to try out; save Sun C++ 5.11 and Sun C++ 5.12.
Should that be a bug? If so, does anyone know if it has been reported to the vendor (currently Oracle)?
Edit:
I'll accept an answer that provide the proper relevant quotations from either the C++03 or C++11 standards documents. Or if you can provide information about a bug report with Oracle.
Upvotes: 4
Views: 163
Reputation: 6181
I just read most of the C++98 standard, chapter 14. There isn't really much said about what type are resulting (specialized) template member, so I assume that it follows the idea that being a template method doesn't make it any less of a method. I f I have a moment, I will see if C++11 says more about it.
From my general idea about C++ I know that your code should pass - and majority of compilers agreeing on that is also a clue, isn't it? :)
Upvotes: 0