Topic: Multiple Inheritance and Ambiguity
Author: swf@ElSegundoCA.NCR.COM (Stan Friesen)
Date: Wed, 27 Jul 94 12:43:22 PDT Raw View
In article <WIKMAN.94Jul26112435@king.trs.ntc.nokia.com>, wikman@ntc.nokia.com writes:
|>
|>
|> void Controller::inform()
|> {
|> EntryDeleted ed;
|> EntryAdded ea;
|>
|> publish(ed); <---
|> publish(ea); <---
|> }
|>
|>
|> At the arrows my compiler complains about ambiguity, even if the two
|> inherited publish methods have different signatures and the template
|> arguments are completely unrelated.
Yep, it does, and it is supposed to.
|>
|> ARM discusses ambiguities when multiple inheritance is used, but as
|> far as I can see ambiguity should be a problem only when the
|> signatures are identical. Anyone care to comment?
|>
This is because fo the way name resolution is done.
Simplifying a bit:
First: A search is made for *any* instance of the name in any
enclosing scope (signature ignored). The first such
name found is used. If the name is found in two or more
distinct scopes and one does not dominate the other,
an ambiguity is declared. (Note - signatures do not
come into play yet).
Second: *If*, and *only* if there is more than one function with
the same name in the *same* *scope*, matching is done on
function signatures to determine which of them to use.
[That is, overloading only applies *within* a scope,
never between].
Since your two instances of the function are in different scopes,
overloading does not apply.
You will have to qualify the calls as follows:
Publisher<EntryDeleted>::publish(ed);
Publisher<EntryAdded>::publish(ea);
If you wish, you can make two inline functions in class Controller
overloaded the way you want which simply call the fully qualified
name of the proper base class function.
--
swf@elsegundoca.ncr.com sarima@netcom.com
The peace of God be with you.
Author: wikman@king.trs.ntc.nokia.com (Johan Wikman)
Date: 26 Jul 94 11:24:35 Raw View
Hi,
Consider the following:
template<class T>
class Publisher
{
protected:
Publisher();
virtual ~Publisher();
void publish(const T&);
};
class EntryDeleted {};
class EntryAdded {};
class Controller : Publisher<EntryDeleted>,
Publisher<EntryAdded>
{
private:
void inform();
};
void Controller::inform()
{
EntryDeleted ed;
EntryAdded ea;
publish(ed); <---
publish(ea); <---
}
At the arrows my compiler complains about ambiguity, even if the two
inherited publish methods have different signatures and the template
arguments are completely unrelated.
ARM discusses ambiguities when multiple inheritance is used, but as
far as I can see ambiguity should be a problem only when the
signatures are identical. Anyone care to comment?
Johan
--
--
Johan Wikman
wikman@ntc.nokia.com; C=FI,A=Elisa,P=Nokia Telecom,S=Wikman,Gi=Johan
TL4E - P.P. Box 12, SF-02611 Espoo 61, Finland