相关疑难解决方法(0)

使用带成员函数指针的decltype

我在使用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;
}
Run Code Online (Sandbox Code Playgroud)

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

decltype剥离了一种类型的"成员"属性?如果是这样,为什么?

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

请帮忙.

编辑:

向微软报道

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

9
推荐指数
1
解决办法
1983
查看次数