我在为成员函数指针使用 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
,我都需要获取成员函数的类型。
请帮忙。
编辑:
最佳答案
为了正式起见(有问题的答案),这似乎是 VC2010 编译器中的一个错误。提交错误报告,以便 Microsoft 可以在下一个版本中修复它。
关于c++ - 将 decltype 与成员函数指针一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557565/