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 8265549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:50:51+00:00 2026-06-08T04:50:51+00:00

Suppose you have the following code template<typename T,void (T::*m)(int)> struct B{ void f(T* a,int

  • 0

Suppose you have the following code

template<typename T,void (T::*m)(int)>
    struct B{

    void f(T* a,int x){
        (a->*m)(x);
    }
};


struct A{


   template<typename X> void f(int){
  }

   void wrap(int i){
     f<char>(i);
   }

   B<A,&A::f<char> > y;
};


int main(){
   A a;
}

This definition

B<A,&A::f<char> > y;

works with gcc,but not with Visual studio 2010:

error C2440: 'specialization' : cannot convert from 'overloaded-function' to 'void (__thiscall A::* )(int)'

On the contrary,

 B<A,&f<char> > y;

works with visual studio but not with gcc.

Note that B<A,&A::f<char> > y; placed in the main, i.e.

  int main(){
       B<A,&A::f<char> > y;
    }

works for VS as well.

IS B<A,&f<char> > y; not standard? is there a way (apart wrapping the template function) to make the thing compile with both compilers?

===EDIT====

A possible, dirty solution is

#ifdef _WIN32
#define vsFix(a,b) b
#else
#define vsFix(a,b) a::b
#endif

 B<A,&vsFix(A,f)<char> > y;
  • 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-06-08T04:50:52+00:00Added an answer on June 8, 2026 at 4:50 am

    IS B<A,&f<char> > y; not standard?

    No. &f<char> is a pointer to function, not pointer to member function.

    is there a way (apart wrapping the template function) to make the thing compile with both compilers?

    Yes, by fixing the types, and passing pointer to object of type A :

    template<typename T,void (T::*m)(int)>
    struct B{
    
        void f(T* a,int x){
            (a->*m)(x);
        }
    };
    
    
    struct A{
    
       template<typename X> void f(int){
      }
    
       void wrap(int i){
         y.f(this, i);
       }
    
       B< A, &A::f<int> > y;
    };
    
    
    int main(){
       A a;
       a.wrap(5);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following code: #include <vector> struct A { int a; int
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose I have following code def foo(x:Int):Unit = { if (x == 1) println
Suppose the following template definition (the code is meaningless): template<class X, class Y> bool
suppose you have the code template <template<class> class BaseType> class EST16 : public BaseType<int>
Suppose I have the following code that I wish to refactor: int toFuture() {
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following code to collect all the possible combinations. abArray =
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some

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.