TITLE: what use are elaborated type names? PROBLEM: matth@extro.ucc.su.OZ.AU (Matthew Hannigan) This article inspires me to post an interesting little example of a function hiding a constructor: A little wrapper class for an int: #include class g { public: int p; g() { p = 7777; }; operator int() {return p;}; }; main() { cerr << g() << endl; } works fine; however putting a function: int g() { return 9999; }; before main() _silently_ overrides the constructor (tested under Sun's CC 4.0.1 and g++ 2.6.3). RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 27 June 95 It doesn't override the constructor, it hides the type name. Because the type name isn't visible, you cannot refer directly to the constructor. For example, you cannot declare g x; but have to use the elaborated type name: class g x; This result is due to a C compatibility wart that wasn't in early C++, but was added in (I think) 1989. The problem is that C allows struct x { ... } x; struct y { ... }; int y; C++ originally did not allow these conflicts, since the same name in the same scope would refer to different things. But the restriction broke too much C code being ported to C++. An object, typedef, or function name is thus allowed in the same scope as a class name, and hides the unelaborated class name.