🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #2010

possible type conversion bug...

#2010
From: Gregg Whitcomb
Date: Thu, 18 May 1989 20:44
54 lines
1728 bytes
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.edu
Technical Details
Message-ID: <8905182044.AA03377@eros.berkeley.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!tut.cis.ohio-state.edu!EROS.BERKELEY.EDU!whitcomb

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!tut.cis.ohio-state.edu!EROS.BERKELEY.EDU!whitcomb
From: whitcomb@EROS.BERKELEY.EDU (Gregg Whitcomb)
Newsgroups: gnu.g++.bug
Subject: possible type conversion bug...
Message-ID: <8905182044.AA03377@eros.berkeley.edu>
Date: 18 May 89 20:44:40 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 54