c++ - 将 decltype 与成员函数指针一起使用

标签 c++ visual-studio visual-studio-2010 templates c++11

我在为成员函数指针使用 decltype 时遇到了一些问题:

#include <iostream>
#include <type_traits>

struct A
{
    void func1() {}
    typedef decltype(&A::func1) type;
};

int wmain(int argc, wchar_t* argv[])
{
    typedef decltype(&A::func1) type;

    //Case 1
    std::wcout
        << std::boolalpha
        << std::is_member_function_pointer<type>::value
        << std::endl;

    //Case 2
    std::wcout
        << std::boolalpha
        << std::is_member_function_pointer<A::type>::value
        << std::endl;

    system("pause");
    return 0;
}

案例 1 按预期打印 true,但案例 2 打印 false

decltype 是否剥离了类型的“成员”属性?如果是,为什么?

此外,有没有办法防止这种行为?无论我在哪里使用 decltype,我都需要获取成员函数的类型。

请帮忙。

编辑:

Reported to Microsoft

最佳答案

为了正式起见(有问题的答案),这似乎是 VC2010 编译器中的一个错误。提交错误报告,以便 Microsoft 可以在下一个版本中修复它。

关于c++ - 将 decltype 与成员函数指针一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557565/

相关文章:

c++ - 为什么静态数据成员可能没有被初始化?

c++ - #在函数C++中定义宏

c++ - 高效地分配许多短命的小对象

winforms - 为什么我的 ColumnHeadersDefaultCellStyle 在 Visual Studio 设计器中不断被重置?

visual-studio - 如何检查 Visual Studio 2013 上安装了哪个更新

visual-studio-2010 - VS2010 安装项目 : Can't create shortcut

c++ - 如何将分数纪元时间戳( double )转换为 std::chrono::time_point?

javascript - Visual Studio Javascript BreakPoint 没有被击中,为什么?

visual-studio-2010 - 在 Visual Studio 中跟踪更改、更新和 TODO

c# - MS Office Visual Studio 加载项、共享加载项和 Excel 2010 加载项之间有什么区别?