Failed to infer template argument for T * from FieldType * (Visual C ++ only)

This code compiles OK on g ++ ( Coliru ) , but not Visual C ++ ( rextester ) - both on the Internet and on my desktop.

This is a simplified version of the much larger Visual Studio 2015 project.

class AAA{
    public: template<class T> static T*  test(T* hqi){
        return hqi;
    }
};
class TTT3{ 
    public: int d;   //In real case, it is some class, but same error nonetheless.
    decltype(AAA::test(&d)) dfd=AAA::test(&d);  //<-- error only Visual C++
};
int main(){
    int b;
    decltype(AAA::test(&b)) dfd=AAA::test(&b);  //OK for boths
}

'T * AAA :: test (T *)': could not infer the template argument for 'T' from 'int TTT3 ::'

Question

  • Why? Is my code wrong? - I do not think so.
  • How to do compilation in Visual C ++? I need it.
+4
source share
2 answers

Visual Studio. :

[expr.unary.op/4]

, - , . [ , is, & (-id), , " ". , - " -", l " " ([conv.func]). & unqualified-id - , -id. - ]

- , V++ decltype - . , Microsoft , , - :

template<class C, typename T>
static T* test(T C::*);

, #ifdef/#endif, V++. , , decltype, .

+1

, &d

decltype(AAA::test(&d)) dfd=AAA::test(&d);

this . , this decltype, , &d &this->d.

, , d typedef .

+1

Source: https://habr.com/ru/post/1676024/


All Articles