2011-07-02 76 views
9

我使用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; 
} 

案例1個打印true如預期,但案例2打印false

decltype去掉類型的「成員」屬性?如果是這樣,爲什麼?

另外,有沒有辦法來防止這種行爲?無論我在哪裏使用decltype,我都需要獲取成員函數的類型。

請幫忙。

編輯:

Reported to Microsoft

+2

似乎在當前MSVC實現中使用'decltype'的另一個限制... – Xeo

+5

剛剛使用gcc 4.7進行檢查,它會爲兩種情況輸出「true」。 – Vitus

+2

@Xeo @Vitus謝謝。微軟破壞了所有的東西...... – Nubcase

回答

3

講禮節的緣故(具有問題的答案),這似乎是在VC2010的編譯器的bug。提交錯誤報告,以便Microsoft可以在下一個版本中修復它。