0

This question relates to Call a class method inside a function which was passed as a string parameter

I have two class hierarchies. The most base classes for each are obj_t and obj2_t.

I have a generic template

template<typename retval_t>
retval_t obj2_t::getProperty(
        const obj_t& obj,
        const retval_t (obj2_t::*fProp)(const vec_t&, const string&, const int) const,
        const retval_t (obj_t::*fAggregate)(const retval_t&) const,
        const vec_t& vec,
        const string& s,
        const int i)
{
    retval_t retval = getPropertySingle<retval_t>(fProp, vec, s, i);
    return (obj.*fAggregate)(retval);
};

Each fProp has its corresponding fAggregate. I want to use the method as

int obj2_t::getX(
        const obj_t& obj,
        const vec_t& vec,
        const string& s,
        const int i)
{
    int retval = getProperty<int>(obj, &obj2_t::getXSingle, &obj_t::AggregateX, vec, s, i);
    return retval;
};

It worked fine in one case. But in another case where AggregateX was overloaded in class obj_t I got compilation error cannot convert ‘<unresolved overloaded function type>’ to ... even if there was no ambiguity in which overload was usable.

Why do I need to specify the overload, and how do I do that?

Extra "curiosity" question: Are there other problematic cases (not solved with the same solution as this) that appear when passing derived classes for obj?

0 Answers0