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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:20:59+00:00 2026-06-15T17:20:59+00:00

I need to pass a distance-function to a template. Therefore I use boost::function and

  • 0

I need to pass a distance-function to a template. Therefore I use boost::function and boost::bind. But I do not understand what I have to pass for class Distance:

template<class DataType, class Point, class Distance>
class CoverTree
{
    Distance distance;
    ...
    public:
     CoverTree(const Distance& distance) : max_level(default_max_level), min_level(default_max_level), distance(distance) {}
    ...
}

the example by the author of the template looks like this:

float euclidian(const std::vector<float>& p1, const std::vector<float>& p2)
{
    ...
}
int main(int argc, char** argv)
{
    CoverTree<float, std::vector<float>, float (*const)(const std::vector<float>&, const std::vector<float>&)> tree(&euclidian);
    ...
}

Now this is my main:

int main(int argc, char** argv)
{
    AllData myData;
    boost::function<float (const vector<Frame>::const_iterator&, const vector<Frame>::const_iterator&)> j_dist;
    j_dist = boost::bind(&AllData::jaccard_distance, myData, _1, _2);
    myData.AddData("C:\\...");
    cout<<j_dist(myData.DATAx.begin()+20, myData.DATAx.begin()+40)<<endl; //works fine
    CoverTree<float, vector<Frame>::const_iterator, ???> tree(&j_dist);
    ...
}

At first, can somone explain me what (*const) means or where I can read about this?
And second:
I think I wrote everything you need, to tell what to write for ??? but I don’t get it.
I already tried:

boost::function<float (const vector<Frame>::const_iterator&, const vector<Frame>::const_iterator&)

and

float (*const) (const vector<Frame>::const_iterator&, const vector<Frame>::const_iterator&)

but this was nice try and error 🙂

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

    At first, can somone explain me what (*const) means or where I can read about this?

    In the author’s example the distance function is:

    float euclidean(const std::vector<float>&, const std::vector<float>&);
    

    The argument passed to the CoverTree constructor is the address of that function i.e. &euclidean, which is a function pointer of type

    float (*)(const std::vector<float>&, const std::vector<float>&)
    

    The template parameter for CoverTree is simply a const-qualified version of that type. Due to the peculiar “inside out” declarator syntax for functions in C and C++, a const pointer to that function type is declared as:

    float (* const)(const std::vector<float>&, const std::vector<float>&)
    

    This is analogous to a const pointer to int, which is declared as:

    int* const
    

    In your case, you got the type right, it’s:

    boost::function<float (const vector<Frame>::const_iterator&, const vector<Frame>::const_iterator&)
    

    Let’s use a typedef to refer to that:

    typedef boost::function<float (const vector<Frame>::const_iterator&, const vector<Frame>::const_iterator&) distance_func;
    

    but the problem is that you are not passing an argument of that type, you’re passing a pointer to that type:

    CoverTree<float, vector<Frame>::const_iterator, distance_func> tree(&j_dist);
                                                                        ^^^^^^^
    

    You can see this won’t work by doing:

    distance_func f = &j_dist;  // ERROR! cannot convert distance_func* to distance_func
    

    The answer should be to simply to pass an argument of the correct type:

    CoverTree<float, vector<Frame>::const_iterator, distance_func> tree(j_dist);
                                                                        ^^^^^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want add a logger function to a worker class, how to pass a
I need to pass some values to a template and then print the template.
I'm trying to make a class that uses the Levenshtein distance function to compare
I have simple Grid with Image named TestImage and I need pass that Grid
I have these typedefs the problem is I need pass a secure socket as
we have two class A & B: class A{ var $settings; function getinfo(){ $settings['domain']=mydomain;
I need to pass information between two view controllers I have. In the past,
I need to pass javascript date value to vb.net function. Method iam using now:
I have a problem: In my project, I need pass an integer value from
I need to pass a lot of variables to a PHP class from a

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.