Why are two using clauses resolving to the same type seen as ambigious in gcc

Before looking at alias resulting type, (and accessibility)

we look at names

and indeed,

NetworkPacket might be

  • MultiCmdQueueCallback::NetworkPacket
  • or PlcMsgFactoryImplCallback::NetworkPacket

The fact they both point to Networking::NetworkPacket is irrelevant.

We do first name resolution, which results in ambiguity.


You simply can resolve the ambiguity by manually selecting which one you want to use.

class PlcNetwork : 
  public RouterCallback, 
  public PlcMsgFactoryImplCallback, 
  public MultiCmdQueueCallback {

using NetworkPacket= PlcMsgFactoryImplCallback::NetworkPacket; // <<< add this line
private:
    void sendNetworkPacket(const NetworkPacket &pdu);

}

The compiler only looks for the definitions in the base classes. If the same type and or alias is present in both base classes it simply complains that it does not know which one to use. It doesn't matter if the resulting type is the same or not.

The compiler only looks for names in the first step, fully independent if this name is a function, type, alias, method or whatever. If names are ambiguous no further action is done from the compiler! It simply complains with the error message and stops. So simply resolve the ambiguity with the given using statement.