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

String literal matches bool overload instead of std::string

“Hello World” is a string literal of type “array of 12 const char” which can be converted to a “pointer to const char” which can in turn be converted to a bool. That’s precisely what is happening. The compiler prefers this to using std::string‘s conversion constructor. A conversion sequence involving a conversion constructor is known … Read more

Why does pointer decay take priority over a deduced template?

The fundamental reason for this (standard-conforming) ambiguity appears to lie within the cost of conversion: Overload resolution tries to minimize the operations performed to convert an argument to the corresponding parameter. An array is effectively the pointer to its first element though, decorated with some compile-time type information. An array-to-pointer conversion doesn’t cost more than … Read more

How does the method overload resolution system decide which method to call when a null value is passed?

For the exact rules, see the overload resolution spec. But briefly, it goes like this. First, make a list of all the accessible constructors. public EffectOptions ( params object [ ] options ) public EffectOptions ( IEnumerable<object> options ) public EffectOptions ( string name ) public EffectOptions ( object owner ) public EffectOptions ( int … Read more