使用decltype和成员函数指针 [英] Using decltype with member function pointers
问题描述
我对使用 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;
//案例1
std :: wcout
<< std :: boolalpha
<< std :: is_member_function_pointer< type> :: value
<< std :: endl;
//情况2
std :: wcout
<< std :: boolalpha
<< std :: is_member_function_pointer< A :: type> :: value
<< std :: endl;
系统(pause);
return 0;
}
案例1打印 true
如预期,但案例2打印 false
。
是 decltype
剥离类型的member属性?如果是,为什么?
此外,有没有办法防止这种行为?我需要获取成员函数的类型,而不管我使用 decltype
。
请帮助。 p>
EDIT:
为了正式(有问题的答案),这似乎是VC2010的编译器中的一个错误。提交错误报告,以便Microsoft可以在下一个版本中修复它。
I have some trouble using decltype
for member function pointers:
#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;
}
Case 1 prints true
as expected, but Case 2 prints false
.
Is decltype
stripping away the "member" property of a type? If so, why?
Also, is there a way to prevent this behavior? I need to get the type of a member function regardless of where I use decltype
.
Please help.
EDIT:
For the sake of formality (having an answer to the question), this appears to be a bug in VC2010's compiler. File a bug report so that Microsoft can fix it in the next version.
这篇关于使用decltype和成员函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!