dimanche 2 août 2015

C++ name lookup - example from the standard

I need an explanation on this example from standard [basic.lookup.unqual]/3:

typedef int f;
namespace N {
struct A {
    friend void f(A &);
    operator int();
    void g(A a) {
        int i = f(a); // f is the typedef, not the friend
                      // function: equivalent to int(a)
    }
};
}

I would argue that void N::f(A &) is closer than int(a) because it does not involve the type-cast operator. I cannot however be sure because the standard contains only one instance of "type cast".


By the way, compiling that code fails in MSVC2015 (but it works in clang and g++).

Error C2440 'initializing': cannot convert from 'void' to 'int'

Aucun commentaire:

Enregistrer un commentaire