Topic: Is a base class typedef legal in derived contructor init. list?
Author: jamshid@ses.com (Jamshid Afshar)
Date: 1 Mar 1995 22:29:12 GMT Raw View
In article <3iihp2$h6c@seattle.polstra.com>, jdp@polstra.com (John Polstra) wrote:
>>In article <3idrse$k8f@giga.bga.com>, Jamshid Afshar <jamshid@ses.com> wrote:
>> Is it legal to use a typedef to initialize a base class in a
>> constructor as in the following. I seem to remember the ARM grammar
>> does not strictly allow it, but ANSI/ISO probably would.
>> [example elided]
>
>The way I read it, even the ARM allows this. The key phrase is toward
>the end of section 9.1:
>
> A typedef-name (7.1.3) that names a class is a class-name;
>
>So, except for explicitly restricted cases, such a typedef-name should
>be legal anywhere the grammar calls for a class-name.
Thanks, I looked it up and the ARM restrictions on using a
typedef-name in place of a class-name are (from 7.1.3) "The synonym
may not be used after a class, struct, or union prefix and not in the
names for constructors or destructors within the class declaration
itself. For example:
struct S;
typedef struct S T;
struct S {
S();
~T(); // error
};
S::T() {} // okay
So, it does appear that IBM's xlC compiler is just plain wrong
according to even the 1990 ARM when it gives an error for:
class Base {
public:
Base(int);
};
class Derived : public Base {
typedef Base inherited;
public:
Derived(int)
: inherited(i) // ARM legal, but xlC complains
{}
};
Btw, Cfront also gives an error for this code but only in the case
when the Derived ctor is inline. Also, I believe Visual C++ has the
same bug.
Jamshid Afshar
jamshid@ses.com
Author: jdp@polstra.com (John Polstra)
Date: 23 Feb 1995 09:48:18 -0800 Raw View
In article <3idrse$k8f@giga.bga.com>, Jamshid Afshar <jamshid@ses.com> wrote:
> Is it legal to use a typedef to initialize a base class in a
> constructor as in the following. I seem to remember the ARM grammar
> does not strictly allow it, but ANSI/ISO probably would.
>
> [example elided]
The way I read it, even the ARM allows this. The key phrase is toward
the end of section 9.1:
A typedef-name (7.1.3) that names a class is a class-name;
So, except for explicitly restricted cases, such a typedef-name should
be legal anywhere the grammar calls for a class-name.
--
John Polstra jdp@polstra.com
John D. Polstra & Co., Inc. Seattle, Washington USA
"Self-knowledge is always bad news." -- John Barth
Author: jamshid@ses.com (Jamshid Afshar)
Date: 21 Feb 1995 23:10:06 GMT Raw View
Is it legal to use a typedef to initialize a base class in a
constructor as in the following. I seem to remember the ARM grammar
does not strictly allow it, but ANSI/ISO probably would.
class Base {
public:
Base(int);
};
class Derived : public Base {
typedef Base inherited;
public:
Derived(int);
};
Derived::Derived(int i)
: inherited(i) // legal?
{}
Thanks,
Jamshid Afshar
jamshid@ses.com