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

Private virtual function of base is hidden by private virtual function of derived

The following code class A { public: void g(int x) { f(x); } protected: virtual void f(int) = 0; }; class B: public A { protected: virtual void f(float) = 0; private: void f(int x) override final { …
TFM
  • 717
  • 6
  • 21
0
votes
2 answers

C++11/14 friend operator with template template parameter overloading

In the following code, I wanted to achieve the effect of binary operator chaining for the specific type definition I want to use - for trivial operator chaining, that a binary operator returns the same type of object, most of cases just simply…
Dejavu
  • 1,299
  • 14
  • 24
0
votes
1 answer

Overload Resolution: What is the role of explicit and the initialization syntax?

Suppose I have an immutable String class as follows: #include #include class String { public: explicit String(const char *Value) : Size(std::strlen(Value)), Value(new char[Size + 1]) { std::memcpy(this->Value,…
Anirban Sarkar
  • 796
  • 6
  • 14
0
votes
0 answers

How overload resolution happens for two different template methods?

If I have the following template methods: template< typename T > void function( T a ) { cout<<"Template T"< void function( int a ) { cout<<"Function taking Int"<( 2.5 ),…
sajas
  • 1,599
  • 1
  • 17
  • 39
0
votes
1 answer

How to solve function overloading on Octave from different folders but with the same name?

The naming used here as function1, Root, class1 and class2 are just fictitious and does not exist in the code. They are just here to mask their real names, however they explicily represent how the files are disposed on the files system and how they…
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
0
votes
2 answers

overload resolution of function templates

Question is the code. It looks like the 2nd function is more special than the 1st one. Why the more general one is called in the following code? How can I make the other function to be used? template class Base{ public: Base(){} …
Tim
  • 355
  • 1
  • 8
0
votes
2 answers

how to avoid many similar overloads for C strings

Here is the code: template bool eq (const L& lhs, const R& rhs) { return lhs == rhs; } template bool eq(char* lhs, const char(&rhs)[N]) { return String(lhs).compare(rhs) == 0; } template bool…
onqtam
  • 4,356
  • 2
  • 28
  • 50
0
votes
0 answers

overload resolution in implement of boost::bind

// bind.hpp template< class A1 > class list1: private storage1< A1 > { template R operator()(type, F & f, A & a, long) { return unwrapper::unwrap(f, 0)(a[base_type::a1_]); } template
zpeng
  • 101
  • 5
0
votes
3 answers

C# Function Overloading : Ambiguous Call

Getting the ambiguous call as arrangement of parameters are different: short,int / int,short /byte,int / int,byte As Function signature is: 1.Number of arguments/parameters 2.Type of arguments/parameters 3.Arrangement of arguments/parameters Why…
0
votes
2 answers

"Overload resolution failed because no accessible 'New' accepts this number of arguments" when trying to write stringbuilder text into a batch file

I was trying to recreate the sourcecode for a launcher to a game I made that requires making and launching a .bat file. When it came time to wrap up the appended lines into a .bat, I found this error. I have researched, thoroughly even. The reason I…
0
votes
1 answer

template function overloading with template type-parameter-list

Please help to understand below 3 different syntax's #include using namespace std; template class Demo { public: void print_type(){ if(is_same()) cout << "Int type" << endl; …
Jagan Arikuti
  • 365
  • 1
  • 2
  • 11
0
votes
1 answer

Ensuring parameter types when implementing interface and inheriting

I have a problem with Classes and Interfaces. I want to achive that an Interface declaretes a method that takes the type of the implemented class. When I inherit from this class the method should only take the type of the inherited class. Is this…
x3ro
  • 329
  • 1
  • 5
  • 11
0
votes
2 answers

Disambiguate two equally specific, identical signatures (generic methods)

Consider the following class: public class TwoWayMap { public T2 Get(T1 x) { throw new System.NotImplementedException(); } public T1 Get(T2 x) { throw new System.NotImplementedException(); } } If T1…
Sebastian Negraszus
  • 11,915
  • 7
  • 43
  • 70
0
votes
3 answers

Overloading with “const” at end of function declaration

I have 3 attempts to overload function "begin()" class Test { public: //case 1: compiler error int begin(); const int begin(); //case 2:compiler warning: type qualifiers ignored on function return type int begin(); const…
Hai Nguyen
  • 110
  • 8
0
votes
1 answer

function overloading and reading fdump-tree-all output

I was looking into a function overloading problem listed below and found that the following code doesn't compile. #include class Test { static void fun(int i) {} void fun(int i) {} }; int main() { Test t; return 0; } My…
deb
  • 631
  • 1
  • 5
  • 15