whitcomb@EROS.BERKELEY.EDU (Gregg Whitcomb) (05/19/89)
version: g++ 1.35.0
config: vax (ultrix 3.0)
problem: compiler reports ambiguous type conversion when attempting
to pass a "String" to a member function of a subclass accepting
a "char*". The subclass's base class defines the same member function.
example:
#include <stream.h>
#include "String.h"
class z
{
void* v;
public:
void set(void* a) {v = a;}
void* get() {return v;}
};
class x : public z
{
public:
void set(char* a="") {z::set(new String(a));}
String get() {return *((String*)z::get());}
};
class y : public x // get rid of "public" to make it compile
{
public:
void set(char* a="") {x::set(a);}
String get() {return x::get();}
};
main()
{
y a;
a.set(String("hello, world"));
cout << a.get() << "\n";
}
% g++ -g sambtype.cc
In function int main ():
ambtype.cc:31: ambiguous type conversion requested for method `set'
by making class "x" members non-public, it works fine. Shouldn't
the declaration of the class "y" member override any possible confusion
with the member in class "x"? I believe that the problem is more involved
than this demonstrates since the real code which produced the bug was
not fixed by removing the "public" keyword.
-Gregg Whitcomb whitcomb@ic.berkeley.edutiemann@YAHI.STANFORD.EDU (Michael Tiemann) (05/23/89)
That was a bug. I fixed it. Michael