Topic: Kind of Annoying


Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/04/17
Raw View
jah@cais.cais.com (John A Hughes) writes:

>The following doesn't compile, because the calls to foo look ambiguous
>to the compiler:
>
>template<class T>
>class Goo {
>public:
>    void foo(T *) {}
>};
[...]
>class C : public Goo<A>, public Goo<B> {

I believe that if you add

 public:
  using Goo<A>::foo;
  using Goo<B>::foo;

here in the declaration of class C, this will resolve the ambiguities
in the calls below:

>};
>
>main() {
>    A a;
>    B b;
>    C c;
>    c.foo(&a);
>    c.foo(&b);
>}

Unfortunately, however, none of the C++ compilers that I have access
to support this yet.

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Srinivas Vobilisetti <srinivas@tcsi.com>
Date: 1996/04/18
Raw View
I too agree with you, Jah. The ANSI/ISO C++ introduced the reserved word
'using' which will help you to show the base class hidden functions in the
derived class interface. Then you don't need to explicitly disambiguate each
time.

Srinivas Vobilisetti
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: jah@cais.cais.com (John A Hughes)
Date: 1996/04/16
Raw View
[Moderator's note: This article is crossposted between comp.std.c++
and comp.lang.c++, and followups have been set to comp.std.c++.  mha]

The following doesn't compile, because the calls to foo look ambiguous
to the compiler:

template<class T>
class Goo {
public:
    void foo(T *) {}
};

class A {
};

class B {
};

class C : public Goo<A>, public Goo<B> {
};

main() {
    A a;
    B b;
    C c;
    c.foo(&a);
    c.foo(&b);
}

Why is this? Why doesn't the mechanism that checks for which function to call
look at the function signature instead of just the name? I presume this is
related to the following:

class A {
public:
    void goo(A*) {}
};

class B : public A {
public:
    void goo(B*) {}
};

class C : public B {
};

main() {
   A a;
   B b;
   C c;
   c.goo(&a);
   c.goo(&b);
}

which won't compile because B::goo hides A::goo (even though again they
have different signatures). What's the interest of a having function hide
another with a totally different prototype simply because their names match?
Of course I can make these things compile by explicitly disambiguating in each
case, but it's annoying and I can't think of any benefit to this behavior. Why
does it work this way?


jah
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]