Topic: name use in classes
Author: bkline@cortex.nlm.nih.gov (Bob Kline)
Date: 1996/05/06 Raw View
The equivalent of the following code in header files for a popular
database vendor's API is rejected by at least 2 major C++ compilers,
and accepted by the latest versions of at least 3 major C++ compilers
(for one of which we have a healthy respect as far as compliance
with the draft standard).
typedef int foo;
class bar { foo foo; };
Is the use of 'foo' as a member variable name in this context legal or not?
If not, what is the applicable clause which prohibits it?
--
/*----------------------------------------------------------------------*/
/* Bob Kline Stream International */
/* bob_kline@stream.com formerly Corporate Software, Inc. */
/* voice: (703) 522-0820 x-311 fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: clamage@Eng.sun.com (Steve Clamage)
Date: 1996/05/06 Raw View
In article n79@lhc.nlm.nih.gov, bkline@cortex.nlm.nih.gov (Bob Kline) writes:
>
>typedef int foo;
>class bar { foo foo; };
>
>Is the use of 'foo' as a member variable name in this context legal or not?
>If not, what is the applicable clause which prohibits it?
Not valid. See 3.3.6 "Class Scope" [basic.scope.class]. It says in part,
"A name N used in a class S shall refer to the same declaration when
re-evaluated in its context and in the completed scope of S."
By the end of class bar (the "completed scope"), "foo" would be the name of
a data member. In the same scope, it cannot also be a type name, which it
would be up to the declaration of member foo.
---
Steve Clamage, stephen.clamage@eng.sun.com
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]