【问题标题】:Using decltype with member function pointers将 decltype 与成员函数指针一起使用
【发布时间】:2011-09-27 07:19:49
【问题描述】:

我在使用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

【问题讨论】:

  • 似乎是当前 MSVC 实现中 decltype 的另一个限制...
  • 刚刚使用 gcc 4.7 检查,两种情况都输出true
  • @Xeo @Vitus 谢谢。微软毁了一切……
  • @Nubcase:没有必要每次都把垃圾放在微软身上,只是原则上。例如。 Bjarne Stroustrup 说 MS 编译器是最好的... :)
  • clang + libc++ 在这两种情况下也会打印出true

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多