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
1
vote
2 answers

Inheritance resolution

I thought that types would automatically resolve to the deepest part of the hierarchy they could. If Cat : Animal and you call cat->talk(), if Cat overrides a talk() from class Animal, the cat will say "meow", not some weird general Animal…
bobobobo
  • 64,917
  • 62
  • 258
  • 363
1
vote
2 answers

C++ overloaded functions and implicit casts

I have some code that works correctly, but I want to make sure that it will always work correctly under the C++ standard. I've created two types which are implicitly converted to double, and created a sin() function for each of the types. I tested…
Asaf
  • 4,317
  • 28
  • 48
1
vote
3 answers

Variadic templates: choose the tuple element type that has a proper method

I have a class like this: template class Evaluator { public: template Evaluator(Types... args) { list = std::make_tuple(args...); } template bool Evaluate(const T&…
Ghita
  • 4,465
  • 4
  • 42
  • 69
1
vote
3 answers

A generic function to accept both reference types and nullable types to accommodate the "as" keyword possible?

This is pure curiosity/challenge, no practical importance at all. So I'm not looking for alternate solutions that get the job done. From this question Most efficient way to check for DBNull and then assign to a variable? I found this answer which…
nawfal
  • 70,104
  • 56
  • 326
  • 368
1
vote
2 answers

Overload resolution when applying operator | to enums of distinct types

After reading the recent question Operations between different enum types are allowed in another enum declaration but not elsewhere I've come up with this example: enum Alpha : long { X, } enum Beta : ulong { X, …
Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
1
vote
5 answers

Why are these overloaded function calls ambiguous?

Why are the following overloaded function calls ambiguous?? With the compile error: call of overloaded 'test(long int)' is ambiguous,candidates are: void test(A)| void test(B)| The code: class A { public: A(int){} …
hu wang
  • 411
  • 3
  • 12
0
votes
1 answer

Using Bind to produce a parameterless function results in error

I am trying to figure out the proper use of std::bind with a boost::signal2 signal. The error set I am getting with clang++ (from Xcode 4.2.1) is: ~/Projects/Myron/Myron/main.cpp:29:59: error: reference to '_1' is ambiguous [3] …
Jeffrey Drake
  • 805
  • 10
  • 26
0
votes
1 answer

Is there a good way here to allow users to both retain access control for properties and overload indexing methods?(matlab 2020a)

Assuming a member within a class has private access properties, i.e., GetAccess=private, if we use a "." type reference for that member in the overloaded subsref method, then the access property of that member becomes invalid at that…
0
votes
2 answers

How to overload A{n} in a custom class? matlab 2020a

Background knowledge subsref Some explanations in the book (published in 2014): When overloading the subsref method, you can use a switch statement to select the type of index and obtain the actual index value. The following three code snippets…
0
votes
0 answers

Function Overload Resolution - Between Const Lvalue Ref and Rvalue Ref

I came across the following C++ code - class C { public: C() { std::cout << "1"; } C(C const&) { std::cout << "2"; } C(C&&) { std::cout << "3"; } ~C() { std::cout << "4"; } }; void g(C const&) { std::cout << "7"; } void g(C&&) { …
Jerry
  • 1
0
votes
0 answers

Why does compiler select a general overload than a specific overload?

Here is the thing, I have two overloads for a method which accepts IDictionary and IEnumerable. Now for the most part almost always the compiler selects appropriate overload when called on an object. But sometimes when the Dictionary becomes…
Eiconic
  • 3,436
  • 1
  • 10
  • 19
0
votes
1 answer

Function Overloading failed

When comparing two methods, if one method has a better match than the other solely based on the method's signature. And that better match ,method fails after deduction, why does the compiler directly report an error? And it seems not comply with the…
Tim H
  • 3
  • 2
0
votes
0 answers

C++ template ambiguous overload, single function

While trying to wrap my head around templates, I quickly ran into, what seems to be an incongruous mess of standards and it's implementation quirks between gcc and clang. Without further ado, here's my very simple template function that implements a…
AjB
  • 890
  • 13
  • 34
0
votes
2 answers

How do we dispatch to different class methods based on the number of input arguments?

We want to have a class with two methods of the same name, however: there exists a method which accepts exactly one argument. The other method accepts two or more arguments. Maybe, to implement multi-dispatching a person can download a third…
0
votes
0 answers

Scala implicit resolution for type (in)equality

The following code import shapeless._ // =:!= class G[T1] { def as[T2](implicit ev: T1 =:= T2): Unit = ??? def as[T2](implicit ev: T1 =:!= T2): Unit = ??? } val g = new G[Int] g.as[Int] results in the following compilation error: ambiguous…
Kamil Kloch
  • 333
  • 1
  • 9