Topic: Name hiding


Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 26 May 1994 01:27:56 GMT
Raw View
Consider the following:

struct A {
 int B;
 A (char *);
};

struct B {
  B (char *);
};

struct C: public A, public B {
  C(): A("Hi"), B("Hello") { }
  void f () { B = 1; }
};

What is the interpretation of `B' in the mem-initializer list for C::C()?
Does it refer to the base class or to the integer member?  What is the
interpretation of `B' in C::f()?

My inclination is to declare both uses to be ambiguous.  Cfront considers
the base class to hide the member in both situations.  xlC considers
the base class to hide the member in the mem-initializer list, but it
considers the member to hide the base in the member function (!!).  g++
2.5.8 considers both uses to be ambiguous (though the current development
compiler does not).

Thoughts?

Jason




Author: p150651@cc.tut.fi (Pulkkinen Esa)
Date: 26 May 94 14:44:40
Raw View
In article <JASON.94May25182756@deneb.cygnus.com> jason@cygnus.com (Jason Merrill) writes:

   Consider the following:

   struct A {
    int B;
    A (char *);
   };

   struct B {
     B (char *);
   };

   struct C: public A, public B {
     C(): A("Hi"), B("Hello") { }
     void f () { B = 1; }
   };

   What is the interpretation of `B' in the mem-initializer list for C::C()?
   Does it refer to the base class or to the integer member?  What is the
   interpretation of `B' in C::f()?

   Thoughts?

The initialization of B should IMHO be interpreted to refer to the base class
(constructor) of C. That's because I think you can't initialize individual
base class members using the base-class initialization syntax, only
the members of the derived class, and base classes using their constructors.

The B in C::f() is ambiguos.
---
   Esa Pulkkinen, esap@cs.tut.fi