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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:44:25+00:00 2026-06-09T00:44:25+00:00

Why is it that I have to change the int * to a typedef

  • 0

Why is it that I have to change the int * to a typedef int * IntPtr for this to compile?

template <class T>
class A
{
    public:
        template <class X>
        void a(X *x, void (X::*fun)(const T&))
        {
        }
};

typedef int * IntPtr;

class B
{
    public:
        B() : a()
        {
            a.a(this, &B::foo); // this won't work
        }
        void foo(const int *&) // must replace `int *` here with `IntPtr`
        {
        }
        A<int *> a; // ...and here
};

class C
{
    public:
        C() : a()
        {
            a.a(this, &C::foo);
        }
        void foo(const IntPtr&)
        {
        }
        A<IntPtr> a;
};

I understand why typedefs are useful but not why they are required. the class C compiles fine B does not.

This is the error from MSVC++ 2008 compiler:

Error   1   error C2784: 'void A<T>::a(X *,void (__thiscall X::* )(const T &))' : could not deduce template argument for 'void (__thiscall X::* )(const T &)' from 'void (__thiscall B::* )(const int *&)'
  • 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-09T00:44:26+00:00Added an answer on June 9, 2026 at 12:44 am

    const int*& and typedef int* IntPtr; const IntPtr& are not the same. In the first case it’s the int that’s constant, in the second case it’s the pointer. Only the second case is compatible with your template.

    If you write

    void foo(int * const &);
    

    instead, it should compile and work just fine.

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

Sidebar

Related Questions

Let's say I have a class: class NumberCollection { public: typedef std::set<int> SetType; typedef
I have a dictionary that goes like this: typedef struct dictNode { int key;
I have a class which I cant change (SuperClass) that has an interface for
I have code as such: typedef intptr_t ptr_t; const int num_elements = 100; ptr_t
I have this very simple wrapper template: template<class T> struct wrapper { inline operator
I have never see a grammar in c++ like this before: typedef int (callback)(int);
Change all links that have an image in it to: javascript(alert(thehref)); eg. <a href=/galleries/anna-leah-111827/image01.html><img
I need change background of all text that have two spaces from the start
I have a change tracking framework that tracks changed made to domain objects on
My situation is that: I have a button that change background of my parent

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.