Topic: Base class can't be typedef. Why?
Author: "Garry Lancaster" <glancaster@ntlworld.com>
Date: Wed, 6 Mar 2002 04:39:35 GMT Raw View
Dear All
Am currently writing some somewhat hairy template
code that involves me deriving from a class type that
is buried deep within a load of templated and typedef'd
code. And therein lies the problem. I want to use
a typedef to simplify my base class type e.g. I want
to write
typedef my_incredibly_long_type_name short_name;
class derived : public short_name
{...};
rather than
class derived : public my_incredibly_long_type_name
{...};
(In reality the long name is even longer and I
use it elsewhere making the typedef more beneficial
than in this cut down example.)
However para 7.1.3/4 of the standard says:
"A typedef-name that names a class is a class-name (9.1).
If a typedef-name is used following the class-key
in an elaborated-type-specifier (7.1.5.3) or in the
class-head of a class declaration...the program is ill-formed."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The class-head includes the part that specifies
base classes. Therefore I am prevented from
using my typedef name there.
Is my interpretation of the standard correct? If so,
what is the rationale behind this decision?
It seems bizarre; after all, I can quite happily use
my typedef name to declare a data member. And
what is a base class in reality but a data member
with a bit of extra compiler magic thrown in?
Kind regards
Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Jens Kilian <Jens_Kilian@agilent.com>
Date: Wed, 6 Mar 2002 21:01:51 GMT Raw View
"Garry Lancaster" <glancaster@ntlworld.com> writes:
> However para 7.1.3/4 of the standard says:
>
> "A typedef-name that names a class is a class-name (9.1).
> If a typedef-name is used following the class-key
> in an elaborated-type-specifier (7.1.5.3) or in the
> class-head of a class declaration...the program is ill-formed."
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I would parse this paragraph as
"If a typedef-name is used
following the class-key in an elaborated-type-specifier (7.1.5.3)
or
following the class-key in the class-head of a class declaration (9)
[...] the program is ill-formed."
Is this worth a defect report for unclear language?
--
mailto:jjk@acm.org phone:+49-7031-464-7698 (TELNET 778-7698)
http://www.bawue.de/~jjk/ fax:+49-7031-464-7351
PGP: 06 04 1C 35 7B DC 1F 26 As the air to a bird, or the sea to a fish,
0x555DA8B5 BB A2 F0 66 77 75 E1 08 so is contempt to the contemptible. [Blake]
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Garry Lancaster" <glancaster@ntlworld.com>
Date: Thu, 7 Mar 2002 17:06:08 GMT Raw View
Garry Lancaster:
> > However para 7.1.3/4 of the standard says:
> >
> > "A typedef-name that names a class is a class-name (9.1).
> > If a typedef-name is used following the class-key
> > in an elaborated-type-specifier (7.1.5.3) or in the
> > class-head of a class declaration...the program is ill-formed."
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jens Kilian:
> I would parse this paragraph as
>
> "If a typedef-name is used
> following the class-key in an elaborated-type-specifier (7.1.5.3)
> or
> following the class-key in the class-head of a class declaration (9)
> [...] the program is ill-formed."
Of course! Thanks, that makes a lot more sense.
> Is this worth a defect report for unclear language?
I'm not sure.
Kind regards
Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]