Why does overload of template and non-template function with the “same signature” call the non-template function?

Because the second overload is not a template. When a template function and a non-template function are both viable for resolving a function call, the non-template function is selected. From Paragraph 13.3.3/1 of the C++ 11 Standard: […] Given these definitions, a viable function F1 is defined to be a better function than another viable … Read more

C# – How can I “overload” a delegate?

Imagine for a moment this was possible. Suppose I could have an overloaded delegate: public delegate void OneDelegate(int i); public delegate void OneDelegate(string s); Now imagine I declare a variable of this type and then assign a function to it, for example: OneDelegate myDelegate = StringMethod; where StringMethod is declared thusly: public void StringMethod(string s) … Read more

What is the use/advantage of function overloading?

IMO, the primary benefit is consistency in the naming of methods / functions which logically perform very similar tasks, and differ slightly in by accepting different parameters. This allows the same method name to be reused across multiple implementations. e.g. The overloads: (Good) function Person[] FindPersons(string nameOfPerson) { … } function Person[] FindPersons(date dateOfBirth) { … Read more

LD_PRELOAD equivalent for Windows to preload shared libraries

AppInit_DLLs. http://support.microsoft.com/kb/197571 But see also: AppInit_DLLs should be renamed Deadlock_Or_Crash_Randomly_DLLs https://web.archive.org/web/20080625171611/http://blogs.msdn.com/oldnewthing/archive/2007/12/13/6648400.aspx You may also want to look into “DLL Injection”. Four approaches (including AppInint_DLLs) are described here: http://en.wikipedia.org/wiki/DLL_Injection

C++ bool returns 0 1 instead of true false

You can use std::boolalpha: Sets the boolalpha format flag for the str stream. When the boolalpha format flag is set, bool values are inserted/extracted as their names: true and false instead of integral values. This flag can be unset with the noboolalpha manipulator. The boolalpha flag is not set in standard streams on initialization. std::cout.setf(std::ios::boolalpha); … Read more

Java overloading and inheritance rules

The behavior of these method calls is dictated and described by the Java Language Specification (reference section 8.4.9). When a method is invoked (ยง15.12), the number of actual arguments (and any explicit type arguments) and the compile-time types of the arguments are used, at compile time, to determine the signature of the method that will … Read more

How can I approximate method overloading?

Yes, there is, and you almost got it already. Traits are the way to go, but you don’t need trait objects, use generics: #[derive(Debug)] enum IntOrFloat { Int(i32), Float(f32), } trait IntOrFloatTrait { fn to_int_or_float(&self) -> IntOrFloat; } impl IntOrFloatTrait for i32 { fn to_int_or_float(&self) -> IntOrFloat { IntOrFloat::Int(*self) } } impl IntOrFloatTrait for f32 … Read more

Method overload resolution unexpected behavior

Yes – the constant 0 is implicitly convertible to any enum type. The constant 1 is only explicitly convertible to the enum type. Both are implicitly convertible to object (via boxing) but the conversion to the enum is preferred where it’s available. Note that this has nothing to do with what values the enum defines. … Read more

Why doesn’t autoboxing overrule varargs when using method overloading in Java 7?

I guess it’s related to bug #6886431, which seems to be fixed in OpenJDK 7 as well. The problem is that JLS 15.12.2.5 Choosing the Most Specific Method says that one method is more specific than another one when types of formal parameters of the former are subtypes of formal parameters of the latter. Since … Read more