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

  • Home
  • SEARCH
  • 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 7491165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:56:00+00:00 2026-05-29T15:56:00+00:00

I am attempting to write a function which will operate on a std::map of

  • 0

I am attempting to write a function which will operate on a std::map of any key and class pointer given to it, and create a new std::map with an index based on the return value of a function in the class. Essentially, a template function to re-index a map based on a function in its contained class. However, I am having compiler errors when trying to invoke the function.

template<class AnyType, class ValueType, class FunctionType>
AssocArray<FunctionType,ValueType> reindex( const AssocArray<AnyType, ValueType>& original, FunctionType (*getterFunction)() ) {
    AssocArray<FunctionType, ValueType> ret;
    FunctionType index;
    for(typename AssocArray<AnyType,ValueType>::const_iterator it = original.begin(); it!=original.end(); it++) {
        index = ((*it->second).*getterFunction)();
        ret[index] = it->second;
    }
    return ret;
}

Invoked by:

floatIndexed = reindex( intIndexed, &test::getB );

Where getB is of float type.

This results in the compiler error:

src/World.cpp:78:50: error: no matching function for call to ‘reindex(std::map<int, onathacar::test*>&, float (onathacar::test::*)())’
src/World.cpp:78:50: note: candidate is:
./include/Types.h:123:36: note: template<class AnyType, class ValueType, class FunctionType> std::map<PreservedType, ValueType> onathacar::reindex(const std::map<LookupType, ValueType>&, FunctionType (*)())

I have tried different variations of this, including using “FunctionType (ValueType::*getterFunction)()” and changing “AssocArray” to “AssocArray”. The only one which worked added a fourth template argument:

template<class AnyType, class ValueType, class FunctionType, class SomeType>
AssocArray<FunctionType,ValueType> reindex( const AssocArray<AnyType, ValueType>& original, FunctionType (SomeType::*getterFunction)() ) {

However, this seems like it would potentially allow functions that are not actually members of ValueType to be called, and so I would prefer some other option. I am not even sure what is wrong, as it appears the templates match, at least with the addition of “ValueType::”. Why does the call not match the template, and is there a way to fix it without a fourth templated type?

For more context, Header Containing Implementation and Calling Function.

  • 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-29T15:56:01+00:00Added an answer on May 29, 2026 at 3:56 pm

    You have two problems. The first is that reindex implies that the value types are values, but you use them as pointers:

    AssocArray<float, test*> floatIndexed;
    floatIndexed = reindex( intIndexed, &test::getB );
    

    The second is that reindex‘s second parameter needs to be declared as a member function, not a free function. So reindex should look like this:

    template<class AnyType, class ValueType, class FunctionType>
    AssocArray<FunctionType,ValueType *> reindex( const AssocArray<AnyType, ValueType *>& original, FunctionType (ValueType:: *getterFunction)() ) {
        AssocArray<FunctionType, ValueType*> ret;
        FunctionType index;
        for(typename AssocArray<AnyType,ValueType*>::const_iterator it = original.begin(); it!=original.end(); it++) {
            index = ((*it->second)->*getterFunction)();
            ret[index] = it->second;
        }
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to write a C# component which will expose events. The component
I'm attempting to write a function in assembly that will detect if a longer
Is this possible? I am attempting to write a function for onmousedown that will
I'm attempting to write a function which starts a thread for each contact and
So I am attempting to write a compare function in C which can take
I am attempting to write a function which tries to connect to Redis using
I have the code below, I'm attempting to write a generic function which takes
I am attempting to write a JS function (using prototype in rails) that will
I am attempting to write a one-line Perl script that will toggle a line
I am attempting to write a .NET component. The component will be dropped onto

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.