Topic: Can typedef be used as base class?
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/12/20 Raw View
Max Motovilov <max@int.com> writes:
>Basically the question is in the subject. I looked through the Sept. draft and haven't
>found anything against it (since typedef is a class-name if it names a class).
That is correct. You can use a typedef name that names a class anywhere
a class name is needed.
>But a
>friend of mine told me that he saw some [authoritative] objections to it in this
>newsgroup.
You have the usual rules of scope and accessibility, and you can't use
a typedef name as the name of a constructor or destructor, but I don't
know of any other restrictions offhand.
>In particular I'm interested if it does apply to member typedefs, esp. of
>template classes (is the following code legal?):
>template <class p>
>class A
>{
> ...........
>public:
> typedef A<p> Object;
> ...........
>};
>class B { ....... };
>class C : public A<B>::Object { ....... };
I believe that code is legal, if obscure. I wouldn't be surprised to
find compilers (not to mention human readers) confused by it.
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]