C++ Logo

std-proposals

Advanced search

Ambiguous function overload resolution for multiple inheritance

From: Peter Neiß <me_at_[hidden]>
Date: Mon, 23 Sep 2019 19:16:43 +0200
Hello to all,

i am new to this list, so if i am doing anything wrong please tell me so.

I like to propose the following to make overload resolution more precise.
The following code shows my problem: (testet with gcc, clang, msvc)

struct P {};
struct Q {};

struct A { void f(P){} };
struct B { void f(Q){} };

struct AB: A, B
{
// using A::f;
// using B::f;
};

void main() {
        P p;
        AB ab;
        
        ab.f(p); // is ambiguous
}


For me, it is counter intuitive that the overload resolution mechanism
today is not able to disambiguate the call ab.f(p). So if the candidate
set is composed only of inherited functions, the first implicit parameter
should not be included in the overload resolution.

This has use cases for the observer pattern with exact subject Type.

Thank you,

Peter Neiss

Received on 2019-09-23 12:18:57