简体   繁体   English

应该将基类的函数模板赋值给指向成员函数的指针

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

Should the following code compile in C++98/03? 以下代码应该在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. 保存Sun C ++ 5.11和Sun C ++ 5.12。

Should that be a bug? 这应该是一个错误吗? If so, does anyone know if it has been reported to the vendor (currently Oracle)? 如果是这样,有人知道它是否已报告给供应商(目前是Oracle)?

Edit: 编辑:

I'll accept an answer that provide the proper relevant quotations from either the C++03 or C++11 standards documents. 我将接受一个答案,该答案提供来自C ++ 03或C ++ 11标准文档的适当相关引用。 Or if you can provide information about a bug report with Oracle. 或者,如果您可以向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. 我刚刚阅读了大部分的C ++ 98标准,第14章。关于什么类型的结果(专门的)模板成员没有太多说法,所以我认为它遵循的想法是作为模板方法不会它不是一种方法。 I f I have a moment, I will see if C++11 says more about it. 我有一点时间,我会看看C ++ 11是否会更多地说明它。

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? 根据我对C ++的一般看法,我知道你的代码应该通过 - 大多数编译器都同意这个也是一个线索,不是吗? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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