1

The question is within the code snippet:

#include <algorithm>
#include <utility>
#include <iostream>


struct A {
    static int max(std::pair<int, int> const& pair) {
        return std::max(pair.first, pair.second);
    }

    int use_max(std::pair<int, int> const & p, int const i) {
        // 1) The following works fine:
        // return std::max(i, max(p));

        // 2) The following also works fine:
        // using std::max;
        // return max(i, this->max(p));

        // 3) This does not compile, afaiu cause the A::max did
        // not even got into the overload resolution list due to
        // name look up rules.
        using std::max;
        return max(i, max(p));

        // Question: What do I write here to add A::max into the
        // overload resolution list, e.g., something like:
        // using std::max;
        // using A::max;
        // return max(i, max(p));
    }

};

int main() {
    std::cout << A().use_max(std::make_pair(2, 3), 1);
}
Anton Daneyko
  • 6,528
  • 5
  • 31
  • 59
  • what do you want to achieve? No matter what overloads are considered the call inside `use_max` will always call the same function. Why do you care what overloads are considered when anyhow only one is called? – 463035818_is_not_an_ai Mar 11 '20 at 19:29

1 Answers1

0

using A::max; is not possible since A is a class and not a namespace.

And the answer to your query is simple:

return max(i, A::max(p));

I am not sure what else are you hoping to achieve here.

Update: Thought about it some more and you can modify code this way?

#include <algorithm>
#include <utility>
#include <iostream>
struct B {
    static int max(int A, int B)
    {
        return std::max(A,B);
    }
};
struct A:B{
    static int max(std::pair<int, int> const& pair) {
        return std::max(pair.first, pair.second);
    }
    using B::max;
    int use_max(std::pair<int, int> const & p, int const i) {
        return max(i, max(p));
    }
};
int main() {
    std::cout << A().use_max(std::make_pair(2, 3), 1);
}
user3389943
  • 147
  • 1
  • 7