locked
template deduction with a "ref class" involved

    Question

  • Hi,

    Compiling with Visual Studio 11 Beta, a Metro project with C++/CX,  I've found an issue, which can be easily reproduced with following code.

     
    namespace test
    {
    
    class A
    {
    public:
      int func(int y) { return 1+y;}
    };
    
    ref class B
    {
    public:
      int func(int y) { return 1+y;}
    };
    
    template <typename TClass, typename TRes, typename TArg1>
    void Deduce(TRes (TClass::*pfunc)(TArg1 arg1))
    {
      OutputDebugStringA(typeid(pfunc).name());
    }
    
    void testing()
    {
      Deduce(&A::func); // OK
      Deduce(&B::func); // ERROR C2748
    }
    
    }

     When a "ref class" is involved, it seems the compiler can not deduce accordingly template parameter:

    //error C2784: 'void test::Deduce(TRes (__thiscall TClass::* )(TArg1),TArg1)' : could not deduce template argument for 'TRes (__thiscall TClass::* )(TArg1)' from 'int (__cdecl MobileBroadband::Details::B::* )(int)'

    Providing explicitily template parameters the compilation goes fine, but it shouldn't be needed, I think:

    Deduce<B, int, int>(&B:::func); // OK

    Is it a C++/CX language limitation or is it a bug?

    Regards.

     

    Friday, May 18, 2012 4:39 PM

All replies

  • Hello,

     

    Thanks for your feedback, I will involve more experts to investigate it.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 21, 2012 7:35 AM