This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: multiple inheritance abiguity


I'm new to C++ but I think because you can convert the int to a double, both functions could be called.

My strongest recommendation is don't listen to me -- go do some google searchs. "C++ multiple inheritance ambiguity"

Microsoft has a page that almost applies.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ vclib/html/_mfcnotes_tn016.asp

But, in effect, declare f inside the class M. You can overload it to call C1::f for double and C2::f for int.

HTH
pedz

On Jan 18, 2006, at 7:51 PM, Rich Johnson wrote:

Hi folks--

Compiling the following (with no options) produces an ambiguity error:
>>file:  bug.cpp  >>>>>>>>>
struct C1 { void f( double ){}; };
struct C2 { void f( int ){}; };

class M : public C1, public C2 {};

int main()
{
  double c1;
  M m;
  m.f(c1);
}
<<<<<<<<<<<<<<<<<
The specific error report is:
$ g++ bug.cpp -o bug
bug.cpp: In function `int main()':
bug.cpp:11: error: request for member `f' is ambiguous
bug.cpp:2: error: candidates are: void C2::f(int)
bug.cpp:1: error:                 void C1::f(double)

I've tried both g++(4.0.0 20041026) on Mac OS X 10.4.4, g++(4.0.3 20051201) on debian(powerpc) unstable. and g++-3.3.6 (Debian 1:3.3.6-10). All three report the same error.

Is the code proper C++? If not, what am I missing?
Given that there's there's only one method with a ''void f(double)" signature where's the source of the ambiguity?


Thnx
--rich




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]