overload-resolution

Why is the compiler not selecting my function-template overload in the following example?

Given the following function templates: #include <vector> #include <utility> struct Base { }; struct Derived : Base { }; // #1 template <typename T1, typename T2> void f(const T1& a, const T2& b) { }; // #2 template <typename T1, typename T2> void f(const std::vector<std::pair<T1, T2> >& v, Base* p) { }; Why is it that the followin...

Overloading, generic type inference and the 'params' keyword

Hi, I just noticed a strange behavior with overload resolution. Assume that I have the following method : public static void DoSomething<T>(IEnumerable<T> items) { // Whatever // For debugging Console.WriteLine("DoSomething<T>(IEnumerable<T> items)"); } Now, I know that this method will often be called with a small numb...

Order of operator overload resolution involving temporaries

Consider the following minimal example: #include <iostream> using namespace std; class myostream : public ostream { public: myostream(ostream const &other) : ostream(other.rdbuf()) { } }; int main() { cout << "hello world" << endl; myostream s(cout); s << "hello world" << endl; myostr...

If the address of a function can not be resolved during deduction, is it SFINAE or a compiler error?

In C++0x SFINAE rules have been simplified such that any invalid expression or type that occurs in the "immediate context" of deduction does not result in a compiler error but rather in deduction failure (SFINAE). My question is this: If I take the address of an overloaded function and it can not be resolved, is that failure in the im...

What are the pitfalls of ADL?

Some time ago I read an article that explained several pitfalls of argument dependent lookup, but I cannot find it anymore. It was about gaining access to things that you should not have access to or something like that. So I thought I'd ask here: what are the pitfalls of ADL? ...

Overload Resolution and Optional Arguments in C# 4

I am working with some code that has seven overloads of a function TraceWrite: void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, string Data = ""); void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, bool LogToFileOnly, string Data = ""); void TraceWrite(string Application, LogLevelENUM L...

Why does Scala type inference fail here?

I have this class in Scala: object Util { class Tapper[A](tapMe: A) { def tap(f: A => Unit): A = { f(tapMe) tapMe } def tap(fs: (A => Unit)*): A = { fs.foreach(_(tapMe)) tapMe } } implicit def tapper[A](toTap: A): Tapper[A] = new Tapper(toTap) } Now, "aaa".tap(_.trim) doesn't compile,...

Why does the compiler not resolve this call to a template function?

Hi, In below program why does the compiler generate an error for the call to the printMax template function and not the call to the printMaxInts function? #include <iostream> template<class A> void printMax(A a,A b) { A c = a>b?a:b; std::cout<<c; } void printMaxInts(int a ,int b) { int c = a>b?a:b; std::cout<<c; } int...

Overload resolution and virtual methods

Consider the following code (it's a little long, but hopefully you can follow): class A { } class B : A { } class C { public virtual void Foo(B b) { Console.WriteLine("base.Foo(B)"); } } class D: C { public override void Foo(B b) { Console.WriteLine("Foo(B)"); } public void Foo(A a) { ...

How to dump candidates in function overload resolution?

How can I dump candidate functions (or viable functions or best viable functions) for a function invocation? I know g++ provides an option to dump class hierarchy. (In fact, Visual Studio 2010 provides a similar option, but it's undocumented. I remember reading something about it—maybe in the VC++ team blog—but I can't remember it clea...

Strange compile error regarding overload resolution

This code fragment: namespace ns { struct last; struct first { typedef last next; }; template <typename T> struct chain { chain<typename T::next> next; }; template <> struct chain<last> { }; } using namespace ns; template <typename T> void f(const T& x) // #1 ...

Why NULL is converted to string*?

Hello all, I saw the following code: class NullClass { public: template<class T> operator T*() const { return 0; } }; const NullClass NULL; void f(int x); void f(string *p); f(NULL); // converts NULL to string*, then calls f(string*) Q1> I have problems to understand the following statement template<class T> operator T*() con...