简体   繁体   中英

Should function template of base class be assignable to pointer-to-member-function

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.

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? :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM