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

c# overload resolution rules

suppose the following extension methods: public static string ToFooBarString(this object obj) { ... } public static string ToFooBarString< T >(this IEnumerable< T > obj) { ... } Now i call this over a implementation of the IEnumerable< T >…
lurscher
  • 25,930
  • 29
  • 122
  • 185
-1
votes
1 answer

C++ name lookup inconsistency for template/overloaded functions

I'm building a minimal binary parser/serializer for one of my projects and I got this error that seems inconsistent at first. I have two top functions I want to expose T parse(bytes) and bytevec serialize(T const&) and from these two templated…
petoknm
  • 11
  • 6
-1
votes
1 answer

C# Overload Resolution with type constraint not choosing method I would expect

The method executed is not the one I expected even though the type constraint gives the compiler enough information to choose the correct overloaded method signature Without the generic method it is calling void DoSomething(IInterface obj) as I…
Darketh
  • 33
  • 3
-1
votes
1 answer

Calling an overloaded parent's method from a child class in C++

I'm trying to understand if is possible to call a parent's function member from a child class. Basically I have the following code: struct Parent { template void doFoo(Args&&... args) { std::cout << "parent doFoo"; …
Saturnu
  • 309
  • 1
  • 8
-1
votes
2 answers

distance calculation error in c++

#include #include #include using namespace std; int square(int a){ return a*a; } struct Point{ int x,y; }; int distance (const Point& a,const Point& b){ int k=(int)…
user466534
-1
votes
1 answer

Determine which overload will be called when passing type as reference

I have free functions foo which are overloaded for user defined types X as follows (C being a library type calling foo): template void foo(C&, const X&) {...} I am able to determine at compile-time whether there exists an overload for…
m.s.
  • 16,063
  • 7
  • 53
  • 88
-1
votes
1 answer

overload resolution in c#: Func parameter

Writing this function: static TResult reduce(ParallelQuery source, Func seedFactory, Func aggregator) { …
mookid
  • 1,132
  • 11
  • 19
-1
votes
1 answer

C++ function overload resolution - bool vs string

I've found some unexpected behavior using the VC++2010 compiler with function overloading: struct A { A(); void O(const bool in); //(1) void O(const std::string in);//(2) } Some of the following calls do not resolve like I would…
zdp
  • 119
  • 4
-2
votes
3 answers

Overloading method but the output isn't what I expected

Here is the question: Create a program named TipCalculation that includes two overloaded methods—one that accepts a meal price and a tip as doubles (for example, 30.00 and 0.20, where 0.20 represents a 20 percent tip), and one that accepts a meal…
-2
votes
1 answer

Why is overloaded method selected with direct superclass parameter rather than Object?

public class Main { static void method(A a){ System.out.print("one"); } static void method(B b){ System.out.print("two"); } static void method(Object obj){ System.out.print("three"); } public…
-2
votes
1 answer

C++ basics: unresolved overloaded function type

I am quite new to C++, and probably I had naive problems. I know that there are other smilar questions, but are related to (seems to me) a more complex problems than mine. I am trying to make a firmware for Arduino, using C++ and I've hurt myself…
thexeno
  • 131
  • 1
  • 8
-3
votes
1 answer

C# overload resolution and generics

I have the following methods public static EnumerableAssertions AssertThat(IEnumerable collection) { Debug.WriteLine("Enumerable!"); return new EnumerableAssertions(collection); } public static ObjectAssertions
-3
votes
2 answers

Why is the method with const used instead of the first method which has no const

void print( int & a ){ cout << a << endl; } void print( const int & a ){ cout << 2*a << endl; } void print( float a ){ cout << 3*a << endl; } Why is 2 the output of print(1)?
1 2 3
48
49