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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:35:36+00:00 2026-05-19T04:35:36+00:00

The question is kind of hard to ask without an example so here it

  • 0

The question is kind of hard to ask without an example so here it is:

#include <vector>

struct O
{
};

struct C
{
  template <typename T>
  void function1(void (C::*callback)(const O*));

  template <typename T>
  void function2(void (C::*callback)(const typename T::value_type));

  void print(const O*);
};


int main()
{
  C c;

  c.function1< std::vector<O*> >(&C::print); // Success.
  c.function2< std::vector<O*> >(&C::print); // Fail.
}

The error that I am given is:

error: no matching function for call to ‘C::function2(void (C::*)(const O*))’.

Basically, the only difference between calls is that in function2, I’m more generic since I use the typedef std::vector<O*>::value_type which should resolve to O*, hence similar to function1.

I’m using G++ 4.2.1 (I know it’s old), but Comeau confirms I’m wrong.

Why does the compilation fail?

  • 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-19T04:35:36+00:00Added an answer on May 19, 2026 at 4:35 am

    Your problem is that const typename T::value_type is basically typename T::value_type const which resolves to O* const which is obviously not the same as const O* (which would be O const *, when writing the ptr declaration behind the type (more useful to figure out this behaviour)).

    As for archiving what you want, that entirly depends on what you want. If you want you can use boost type_traits or tr1 type_traits to strip the pointer, add const and make it a pointer again like this:

    template <typename T>
    void function2(void (C::*callback)(typename boost::add_pointer<typename boost::add_const<typename boost::remove_pointer<typename T::value_type>::type>::type>::type));
    

    Using tr1 instead of boost should basically be a matter of replacing boost:: with std::tr1::.

    However I wouldn’t exactly call this a useful generalization, so you might want to overthink if you really want to go that way. Personally I would either use something like boost function or free functions as callbacks, the former allowing for much greater flexibility in what can be used as callbacks (free functions, functors, member functions), while the later at least makes it easy to create a second function which will appropriately convert the arguments (that is if you want to use a function which gets const O* as parameter, you can create one which takes O* and calls the first one with that parameter and use that one as callback).

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

Sidebar

Related Questions

kind of a hard question to word but here are the the tables: *
Question is kind of hard to ask. I'll try my best to explain it.
So I feel like this is kind of a hard question to ask correctly,
The question is kind of hard to word, but here's the idea. I want
Kind of a newbie question here but I promise it is really hard to
Overflow :3 I've got a kind of hard-case question. So I'll try clearly explain
This question might be kind of elementary, but here goes: I have a SQL
I have ask this kind of question before, but it seems my previous question
This is kind of a hard question to describe, and I've searched for about
This is kind of a hard question to formulate. I'm wondering how HttpContext.Current gets

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.