C++ overloaded function as template argument

You can give an explicit template argument: bar<int(int)>(3, foo); or cast the ambiguous function name to a type from which the template argument can be deduced: bar(3, static_cast<int(*)(int)>(foo)); or wrap it in another function (or function object) to remove the ambiguity bar(3, [](int x){return foo(x);});

C++ template functions overload resolution

The unspecialized function templates are also called the underlying base templates. Base templates can be specialized. The overloading rules to see which ones get called in different situations, are pretty simple, at least at a high level: Nontemplate functions are first-class citizens. A plain old nontemplate function that matches the parameter types as well as … Read more

How to use Reflection to Invoke an Overloaded Method in .NET

You have to specify which method you want: class SomeType { void Foo(int size, string bar) { } void Foo() { } } SomeType obj = new SomeType(); // call with int and string arguments obj.GetType() .GetMethod(“Foo”, new Type[] { typeof(int), typeof(string) }) .Invoke(obj, new object[] { 42, “Hello” }); // call without arguments obj.GetType() … Read more

Java overloading and overriding

Method overloading means making multiple versions of a function based on the inputs. For example: public Double doSomething(Double x) { … } public Object doSomething(Object y) { … } The choice of which method to call is made at compile time. For example: Double obj1 = new Double(); doSomething(obj1); // calls the Double version Object … Read more

Why is it not possible to overload class templates?

Section 12.5 from Templates the Complete Guide (Amazon) contains this quote: You may legitimately wonder why only class templates can be partially specialized. The reasons are mostly historical. It is probably possible to define the same mechanism for function templates (see Chapter 13). In some ways the effect of overloading function templates is similar, but … Read more