Questions tagged [overload-resolution]

Overload resolution is a language mechanism to select among several viable function overloads. Its rules are intricate and often surprising, even for experienced users.

Overload resolution is a language mechanism to select among several viable function overloads.

Possible functions overloads are first determined from a candidate list resolution that itself includes inter ala. name lookups, template or generic determination and instantiation, promotions and conversions.

733 questions
0
votes
1 answer

Overriding overloaded member functions that call each other in cpp

I have designed a class which uses overloaded member functions that call each other such that functions with additional arguments modify member variables that the original function relies on. It works as expected/intended when inheritance is not…
0
votes
1 answer

Overload Resolution for comparisons of c++ compare objects

I wanted to introduce the spaceship operator in our Code Base, but we are currently using global templated comparison operators like this: template bool operator > (const L& l, const R& r) { return r < l; } (operator < is…
T.D.
  • 15
  • 4
0
votes
0 answers

C++ Inheritance and Overloaded Methods

I would like some clarification as to the behavior of the following: #include class A {}; class B : public A {}; class Q : public A {}; class C : public B {}; void doOverload(const A& v) { std::cout << __PRETTY_FUNCTION__ <<…
Patrick Wright
  • 1,401
  • 7
  • 13
0
votes
0 answers

Why are members from multiple inheritances of same class template ambiguous?

When inheriting from a class template multiple times, there is the problem that multiple inheritance of these template classes makes member functions ambiguous (also here), because apparently it is defined that way in the standard. Question: Why is…
0
votes
1 answer

Why is my function override for STL class function used even for wrong argument type?

Consider this program: #include #include class MyStack : public std::stack { public: void push(char) { std::cout << "Using char overload of push function.\n"; } }; int main() { MyStack stack{}; …
0
votes
0 answers

cannot convert ‘’ to

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 retval_t…
0
votes
1 answer

What's the relevance of the Note in [over.load]/1?

(You might see this question as a duplicate of this, but, to be honest, I've not really understood the matter, so I'm asking separately with my own wording.) [over.load]/1 reads: Not all function declarations can be overloaded. Those that cannot be…
0
votes
1 answer

Initialization by conversion function for direct reference binding

I found out the rules for determining the candidate conversion functions, for direct reference binding, are not described clearly by the standard at least for me. The rules are found in [over.match.ref] Under the conditions specified in…
mada
  • 1,646
  • 1
  • 15
0
votes
1 answer

How does function template ordering de-prioritize empty function parameter packs in C++?

In the C++20 standard, [temp.func.order] contains the following non-normative example: template void f(T, U...); // #1 template void f(T); // #2 template void…
0
votes
0 answers

How to ensure correct overload resolution with variadic template constructor in C++

I have browsed similar threads, but none have answered my question. I am looking for a way to ensure correct overload resolution with two competing constructors, where one takes two parameters and the other one is a variadic template constructor.…
0
votes
0 answers

Confusion about "perfect match" and "matchb with minor adjustments" in the context of perfect forwarding ctor vs other constructors

I was reading Chapter 25 from C++ Templates - The Complete Guide - 2nd ed., where, given code more or less like this #include template struct Tuple; template struct Tuple { H h; …
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

How to declare the template argument for an overloaded function

I have a fairly big project that, regarding this question, I can summarize with this structure: void do_something() { //... } template void use_funct(F funct) { // ... funct(); } int main() { // ... …
0
votes
1 answer

Error: 'decltype' cannot resolve address of overloaded function

I'm trying to glean the return type of a class method inside a class that could either be const or non-const. This information is transfered to another calling class object where I try to use decltype() to resolve the return type. However, it…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
1 answer

How to determine the best-matched constructor, given a set of properties

Although attributes applied to any class can be queried via reflection, there is no way to determine which constructor overload was called at compile time. In my scenario, I am analyzing all types in an assembly that have the attribute…
Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
0
votes
2 answers

Function template specialization in C++, no Instance of overloaded function

I'm learning about function template specialization in C++ and am tasked with writing a template function called plus that returns the sum of it's two arguments which maybe of different types. One version that accepts by value and another by…