Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:09:46+00:00 2026-05-31T04:09:46+00:00

I am encountering the C2783 error with Visual C++ (could not deduce template argument),

  • 0

I am encountering the C2783 error with Visual C++ (could not deduce template argument), I have the following test case:

enum SPKType { A, B, C, D };

template<SPKType TypeCode, class ObjectType, typename U>
struct SPKSetterPattern
{
    typedef void (ObjectType::* func)(U);
};
template<class ObjectType, typename U>
struct SPKSetterPattern<B,ObjectType,U> { typedef void (ObjectType::* func)(U,U); };
template<class ObjectType, typename U>
struct SPKSetterPattern<C,ObjectType,U> { typedef void (ObjectType::* func)(U,U,U); };
template<class ObjectType, typename U>
struct SPKSetterPattern<D,ObjectType,U> { typedef void (ObjectType::* func)(U,U,U,U); };


template<typename ObjectType, SPKType TypeCode>
struct helper
{
    template<typename U>
    static inline void add(ObjectType* obj, typename SPKSetterPattern<TypeCode,ObjectType,U>::func attrSetter) {}
    //static inline void add(ObjectType* obj, void (ObjectType::*attrSetter)(U)) {}
};

class test
{
public:
template<typename ObjType>
void init()
{
    // Supposed to work
    helper<ObjType,A>::add(this, &test::setA);
    //helper<ObjType,B>::add(this, &test::setB);
    //helper<ObjType,C>::add(this, &test::setC);
    //helper<ObjType,D>::add(this, &test::setD);
    helper<ObjType,A>::add(this, &test::setAf);

    // Supposed to fail
    //helper<ObjType,B>::add(this, &test::setBf);
}

test() { init<test>(); }

void setA(int a) {}
void setB(float,float) {}
void setC(int,int,int) {}
void setD(int,int,int,int) {}

void setAf(double a) {}
void setBf(int,double) {}
};

int main()
{
test t;
return 0;
}

When commenting the line

static inline void add(ObjectType* obj, typename SPKSetterPattern<TypeCode,ObjectType,U>::func attrSetter) {}

and uncommenting the line following, the code compiles.

I don’t understand why, because for me the second argument of ‘helper::add’ is still the same…

Thanks for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:09:48+00:00Added an answer on May 31, 2026 at 4:09 am

    You’re asking the compiler to do a reverse lookup: to find all specializations on U of SPKSetterPattern and all their definitions of func, find the one definition that matches your actual argument, and then deduce the template arguments as those used for that specialization.

    It doesn’t work like that.

    You don’t get reverse lookup for template matching.


    EDIT: due to requests in comment:

    The following code deduces the argument type for a method with all arguments of the same type, and known result type void and class Class:

    template< class Class, class MethodPtr >
    struct ArgType;
    
    template< class Class, class Arg >
    struct ArgType< Class, void (Class::*)( Arg ) >
    { typedef Arg T; };
    
    template< class Class, class Arg >
    struct ArgType< Class, void (Class::*)( Arg, Arg ) >
    { typedef Arg T; };
    
    template< class Class, class Arg >
    struct ArgType< Class, void (Class::*)( Arg, Arg, Arg ) >
    { typedef Arg T; };
    
    template< class Class, class Arg >
    struct ArgType< Class, void (Class::*)( Arg, Arg, Arg, Arg ) >
    { typedef Arg T; };
    

    The original code can then be amended as follows:

    template<typename ObjectType, SPKType TypeCode>
    struct helper
    {
        template< typename U >
        static void ungoodAdd(
            ObjectType*                                             obj,
            typename SPKSetterPattern<TypeCode,ObjectType,U>::func  attrSetter
            )
        {
            (void)obj; (void)attrSetter;
        }
    
        template< typename MethodPtr >
        static void add(
            ObjectType*     pObject,
            MethodPtr       method
            )
        {
            typedef typename ArgType< ObjectType, MethodPtr >::T Arg;
            ungoodAdd<Arg>( pObject, method );
        }
    
        // template<typename U>
        // static inline void add(ObjectType* obj, typename SPKSetterPattern<TypeCode,ObjectType,U>::func attrSetter) {}
        //static inline void add(ObjectType* obj, void (ObjectType::*attrSetter)(U)) {}
    };
    

    However, with access to some C++11 support probably std::function is a better alternative?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am encountering the following bug. I have a class Foo . Instances of
I'm encountering the following error when attempting to (svn) import from within Xcode). Import
I'm encountering the following error at unpredictable times in a linux-based (arm) communications application:
I am randomly encountering the following error: Message: Invalid viewstate. Client IP: xx.xxx.xxx.xx Port:
I'm encountering something I did not expect. I have a C# client that accesses
I have been encountering this error for my project, which involves working with Digital
I'm encountering the following problem - I have simple GWT overlay types, and I'm
I've been encountering the following error when trying to build a session factory: PersistenceTests.Can_Map_Orders_To_Database
I am encountering the following error in my app. upon starting it: [3/26/12 13:05:26:109
I am encountering an exception cause by the CFINVOKEARGUMENT line of the following snippet:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.