【发布时间】: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,我都需要获取成员函数的类型。
请帮忙。
编辑:
【问题讨论】:
-
似乎是当前 MSVC 实现中
decltype的另一个限制... -
刚刚使用 gcc 4.7 检查,两种情况都输出
true。 -
@Xeo @Vitus 谢谢。微软毁了一切……
-
@Nubcase:没有必要每次都把垃圾放在微软身上,只是原则上。例如。 Bjarne Stroustrup 说 MS 编译器是最好的... :)
-
clang + libc++ 在这两种情况下也会打印出
true。
标签: c++ visual-studio visual-studio-2010 templates c++11