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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:31:23+00:00 2026-06-05T17:31:23+00:00

The problem I’m having is that I want to use STL’s sort with a

  • 0

The problem I’m having is that I want to use STL’s sort with a custom compare function inside a templated class.

The idea from using typedef came from another Stackoverflow Post

Anyway, here is the code:

template <typename R,typename S>
class mesh{
  /* some stuff */

  void sortData(){
    typedef bool (*comparer_t)(const S,const S);
    comparer_t cmp = &mesh::compareEdgesFromIndex;
    sort(indx,indx+sides*eSize,cmp);
  }

  /* more stuff */

  // eData and cIndx are member variables
  bool compareEdgesFromIndex(const S a,const S b){
    return compareEdges(eData[cIndx[2*a]],eData[cIndx[2*a+1]],eData[cIndx[2*b]],eData[cIndx[2*b+1]]); 
  }
};

The error I’m getting is

mesh.h:130:29: error: cannot convert ‘bool (mesh<float, unsigned int>::*)(unsigned int, unsigned int)’ to ‘comparer_t {aka\
bool (*)(unsigned int, unsigned int)}’ in initialization

Thank you in advance!

  • 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-05T17:31:25+00:00Added an answer on June 5, 2026 at 5:31 pm

    You are trying to mix a member-function-pointer where a function-pointer is required. You can either refactor the predicate to be a static function, or use bindings to associate your member-function-pointer with an instance of your class mesh.

    In order to bind an instance to your member-function-pointer you would do

    std::bind( mesh_instance, &mesh::compareEdgesFromIndex, _1, _2 )
    

    if working with C++11. If you don’t have the luxury, then you can use equivalent functionality from Boost (replacing std::bind by boost::bind). C++03 offers some binding functionality but it’s limited, and I believe obsoleted now that generic binding functionality is available.

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

Sidebar

Related Questions

Problem I want to validate a field using a custom validator I've created that's
Problem: I have 2 classes, DB class and a User class, that will work
Problem I want to save the attributes of a model that have changed when
Problem: I've written State Machine for my android application. It is separate class, extension
Problem: I have a table that prints out vertical but I would like it
Problem: I am trying to build a recursive tree using a function and data
Problem occured when i tried to display xml data that has been taken by
Problem: I'm working on a website where there is a dial that displays a
Problem: I need an array (datamember) in a parent class A. However, depending on
Problem One: </a> 19-10-2011, 04:49 PM </td> <td class=thread How to fetch the DATE

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.