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

Problems with ParamArray on XDocument constructor

XDocument has an overloaded constructor. XDocument() XDocument([ParamArray] content: obj[]) XDocument(XDocument) XDocument(XDeclaration,[ParamArray] content: obj[]) so when I try to create an XDocument new XDocument( new…
MrD at KookerellaLtd
  • 2,412
  • 1
  • 15
  • 17
0
votes
2 answers

How to fix E2015 "ambiguity between pow(double,double) and pow(float,int)"

I'm doing my homework in C++ Builder 6. When I try to get a cubic root from variable X, I get this error: result = std::pow(x, 1.0 / 3); E2015 Ambiguity between "std::pow(double,double)" and "std::pow(float, int)" What should i do to fix this?…
0
votes
3 answers

Is there a way to force this ambiguity away?

I'd like to supply two forms of a GetLength(psz) style function - one that doesn't know an upper bounds, and one that does: template size_t GetLength(const T * psz) { /* compute size w/o knowing what upper bound may be */ } template…
Mordachai
  • 9,412
  • 6
  • 60
  • 112
0
votes
1 answer

Template function overload resolution of T vs. SomeClass

I want to understand why the void handleParam(const Str& name, Table value) template overload never gets instantiated (note that the code below is illustrative). I'm sure there is a perfectly good reason why it doesn't work, I just want to…
sleep
  • 4,855
  • 5
  • 34
  • 51
0
votes
1 answer

How do I force a Java call to overloaded Kotlin method accepting a non-nulllable parameter?

In Kotlin, I have two overloaded methods defined on an object. They have the same signature except that in one case, a parameter is nullable and in the other case, that same parameter is not. Based on if the passed in parameter is nullable or not,…
CryptoFool
  • 21,719
  • 5
  • 26
  • 44
0
votes
2 answers

Template class member vs. non-member template function ambiguity

I'm developing a header-only library for automatic/algorithmic differentiation. The goal is to be able to simply change the type of the variables being fed to a function and calculate first and second derivatives. For this, I've created a template…
0
votes
2 answers

How to parametrize an algorithm with a custom non-pure swap-function?

I want to apply an algorithm from on ranges of elements, containing in one container, defined by iterator pairs, containing into another one. To do this I need a swap function with state: just pointer to the container with elements to…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
0
votes
1 answer

Called function instance must depend on parameter

I would like to make the function call depend on the parameter, that is, what version of the function is being called. I'm looking for a way to make the following code work, without making enum_value v a template argument. The goal is that if…
0
votes
1 answer

detection idiom and default parameter type match

I can write the following to detect, if an object is serializable. template struct is_serializable : std::false_type {}; template struct is_serializable () <<…
Martin Fehrs
  • 792
  • 4
  • 13
0
votes
1 answer

Why there is ambiguous reference to overloaded definition in this code?

Why there is ambiguous reference to overloaded definition in this code? class A { def m(a1: A, o2: Any): A = { print("1") a1 } def m(a1: A, a2: A): A = { print("2") a1 } def m(o1: Any, o2: Any): Any = { print("3") …
CodingNow
  • 998
  • 1
  • 11
  • 23
0
votes
2 answers

Overload resolution over several layers of inheritance?

Consider the following example with several layers of inheritance: struct A { void operator()(double x); }; struct B: A { using A::operator(); template void operator()(T... x); }; struct C: B { using B::operator(); …
Vincent
  • 57,703
  • 61
  • 205
  • 388
0
votes
0 answers

Cannot call overloaded methods of .NET API in PowerShell

I have a 3rd party API that I want to use in a PowerShell script. I can instantiate the objects and access properties and non-overloaded methods, but every call to an overloaded method fails with Cannot find an overload for "" and the…
aucuparia
  • 2,021
  • 20
  • 27
0
votes
1 answer

Overload resolution, name lookup and function pointers

I have a case where lookup and overload resolution behaves differently: for user-defined class vs built-in types vs std::string for direct call vs function pointer call I cannot figure what exact parts of the standard justify these…
0
votes
0 answers

Rationale behind universal reference template function being a more viable match than non-template function?

Given a template member function (... a templated constructor in a templated class, as it happens) taking a variadic universal reference, and another candidate function (copy constructor, in my case), both GCC and clang select the universal…
Damon
  • 67,688
  • 20
  • 135
  • 185
0
votes
2 answers

How to deal with const T& and T&& instantiating to the same signature?

Basically I want to provide construction from const lvalue versions and rvalue reference versions: transform_iterator(const Functor& f, const Iterator& it) : functor(f), iterator(it) {} …
Incomputable
  • 2,188
  • 1
  • 20
  • 40