我在使用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.
请帮忙.
编辑: