将 decltype 与虚拟成员函数指针一起使用

Using decltype with virtual member function pointers

本文关键字:一起 指针 函数 decltype 虚拟成员      更新时间:2023-10-16

decltype与虚拟成员函数指针一起使用是否合法?

下面使用 VS2012 生成内部错误 (C1001)。

struct C
{
    virtual void Foo() {}
    typedef decltype(&C::Foo) type;   //pointer
}

但这编译得很好:

struct C
{
    virtual void Foo() {}
    typedef decltype(C::Foo) type;   //not pointer
}

这是一个错误吗?

MSVC 在decltype成员函数指针方面存在多个已知问题;另请参阅将 decltype 与成员函数指针一起使用

这是合法语法;g++对此非常满意(http://ideone.com/sTZi6)。 标准中没有任何内容限制decltype对成员函数的操作。