简体   繁体   English

模板成员函数重载问题

[英]Template member function overloading issue

The Standard at N4296::13.1/2.2 [over.load] says: N4296::13.1/2.2 [over.load]的标准N4296::13.1/2.2 [over.load]说:

Likewise, member function template declarations with the same name, the same parameter-type-list, and the same template parameter lists cannot be overloaded if any of them is a static member function template declaration. 同样,如果其中任何一个是静态成员函数模板声明,则不能重载具有相同名称,相同parameter-type-list和相同模板参数列表的成员函数模板声明。

So, I thought that the following program would be ill-formed: 所以,我认为以下程序将是不正确的:

#include <iostream>

struct A
{
    template <typename T>
    static void foo(){ }

    template <typename T>
    static int foo(){ return 0; }
};

int main(){ }

DEMO DEMO

In contrast, the program 相比之下,该计划

#include <iostream>

struct A
{
    static void foo(){ }

    static int foo(){ return 0; }
};

int main(){ }

is ill-formed 是不正确的

DEMO DEMO

Is the first example a bug? 第一个例子是错误吗?

Currently subject of CWG #1252 : 目前CWG#1252的主题:

The Standard does not allow overloading of member functions that differ only in their return type (cf enable_if ). 标准不允许重载仅在其返回类型上不同的成员函数(cf enable_if )。

The wording you quoted is presumably going to be amended, since there is no reason whatsoever to disallow overloading of member function templates based on SFINAE in the return type; 你引用的措辞可能会被修改,因为没有任何理由不允许在返回类型中基于SFINAE重载成员函数模板; I'd regard the standard as defective and the implementations as correct. 我认为标准是有缺陷的,实现是正确的。

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

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