Topic: Are any of these uses of typedef standard c++?
Author: fvali@biotrack.com
Date: 1999/04/16 Raw View
Hi Alf,
thanks for your response. I feel I should make some clarifications
though.
In article <7f1ud5$an$1@nnrp1.dejanews.com>,
"Alf P. Steinbach" <alf_steinbach@my-dejanews.com> wrote:
> In article <7evon0$4js$1@nnrp1.dejanews.com>,
> fvali@biotrack.com wrote:
> > Hi folks, can someone please help me out here and provide some rationale as
> > to why they believe the following fragment of code contains ill-formed or
> > well-formed uses of typedef.
>
> It seems like you're asking about two distinct problems: (1) declarations
> of the form "typedef X X", and (2) how to make something public.
Actually I'm not asking (2). I am familiar with the efficaciousness
of 'using member declarations' in producing such an access decay when
*base class* names are involved.
But I am a little unclear as to when "typedef X X" is well-formed
and when it isn't.
Consider the idiom of selectively dispatching private
names to other nested types:
class Outer
{
struct InnerPriv { };
public:
class InnerPriv___FriendDispatch;
friend class InnerPriv___FriendDispatch;
// friend struct Exception; // Exception should not have access to too much
struct Exception;
class InnerPriv___FriendDispatch
{
// I'd like to be able to replace this line with
// typedef InnerPriv InnterPriv - but i'm not sure if i can
// and if i can't - i'm not sure why not.
typedef InnerPriv tagInnerPriv;
friend struct Exception;
};
struct Exception
{
typedef InnerPriv___FriendDispatch::tagInnerPriv InnerPriv;
...
};
// Now if i want to give a local class access, i can do it two ways.
int process()
{
typedef InnerPriv tagInnerPriv; // I dislike doing this
struct
/* : InnerPriv___FriendDispatch // inheritance could work too */
{
typedef tagInnerPriv InnerPriv; // and it's companion
bool operator()(InnerPriv* p_, InnerPriv* i_ )
{ return p_->val <= i_->val; }
} fork_left;
if( fork_left( ... ) )
...
else
...
}
}; // end class Outer
>
> For problem (1), avoid explicit declarations like this. However, in a
> template it might well be that, say, "typedef Ugga Bugga", where Bugga
> is a template parameter, will translate to "typedef Ugga Ugga", which
> in that context will be valid.
But if you consider what i want to do, it would be neater if i could
just retypedef the name to itself. This would introduce an explicit
declaration exactly in the scope that I want, without introducing
a tag name. Using member declarations are only relevant if the name
is a member of a base class. Else using declarations cannot contain
class names in their nested name specifiers, but only namespace names.
>
> For problem (2), if something is inherited with protected access you
> might make it public by using the "using" keyword after "public:". In
> earlier times the usual method was to redeclare the inherited item.
or items that all have the same name (similar to using member declarations).
I'm still very curious as to why the following use of typedef I I
within the class Outer is ill-formed. Does anyone know?
-thanks
-fais
> > Example:
> > typedef int I;
> > class Outer
> > {
> >
> > // This is an error according to an example (non-normative) in the
> > // standard [refer to 3.3.6] - but can someone explain exactly why?
> >
> > typedef I I;
> >
> > class PrivInner { };
> > class PrivInner2 { };
> > class PrivInner3 { };
> >
> > public:
> > // can we give the same name public access by redefining it using a
> > // a typedef but under different access
> > // refer to 7.1.3 [2]
> >
> > typedef PrivInner PrivInner;
> >
> > // can we redeclare Outer using a typedef? refer to 9.2 [13]
> > // Doesn't this explicitly add a member of type name Outer?
> > // Yes I know there is an implicit addition of Outer for the purposes
> > // of name lookup.
> >
> > typedef Outer Outer;
> >
> > struct PubInner;
> > friend struct PubInner;
> > struct PubInner
> > {
> > // Is this an error since we are retypedefining a name
> > // that has not been originally declared in PubInner's class scope.
> >
> > typedef PrivInner2 PrivInner2;
> > };
> >
> > void memfx()
> > {
> >
> > typedef PrivInner2 PrivInner2; // ill-formed or well-formed?
> > struct
> > {
> > PrivInner2 p2; // if above is well-formed so is this, right?
> >
> > PrivInner3 p3; // ill-formed, right? cannot access
> >
> > } local;
> > }
> >
> > };
>
<snip>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Alf P. Steinbach" <alf_steinbach@my-dejanews.com>
Date: 1999/04/15 Raw View
In article <7evon0$4js$1@nnrp1.dejanews.com>,
fvali@biotrack.com wrote:
> Hi folks, can someone please help me out here and provide some rationale as
> to why they believe the following fragment of code contains ill-formed or
> well-formed uses of typedef.
It seems like you're asking about two distinct problems: (1) declarations
of the form "typedef X X", and (2) how to make something public.
For problem (1), avoid explicit declarations like this. However, in a
template it might well be that, say, "typedef Ugga Bugga", where Bugga
is a template parameter, will translate to "typedef Ugga Ugga", which
in that context will be valid.
For problem (2), if something is inherited with protected access you
might make it public by using the "using" keyword after "public:". In
earlier times the usual method was to redeclare the inherited item. An
alternative is to create a public wrapper method or class.
Hth.,
- Alf
>
> Example:
> typedef int I;
> class Outer
> {
>
> // This is an error according to an example (non-normative) in the
> // standard [refer to 3.3.6] - but can someone explain exactly why?
>
> typedef I I;
>
> class PrivInner { };
> class PrivInner2 { };
> class PrivInner3 { };
>
> public:
> // can we give the same name public access by redefining it using a
> // a typedef but under different access
> // refer to 7.1.3 [2]
>
> typedef PrivInner PrivInner;
>
> // can we redeclare Outer using a typedef? refer to 9.2 [13]
> // Doesn't this explicitly add a member of type name Outer?
> // Yes I know there is an implicit addition of Outer for the purposes
> // of name lookup.
>
> typedef Outer Outer;
>
> struct PubInner;
> friend struct PubInner;
> struct PubInner
> {
> // Is this an error since we are retypedefining a name
> // that has not been originally declared in PubInner's class scope.
>
> typedef PrivInner2 PrivInner2;
> };
>
> void memfx()
> {
>
> typedef PrivInner2 PrivInner2; // ill-formed or well-formed?
> struct
> {
> PrivInner2 p2; // if above is well-formed so is this, right?
>
> PrivInner3 p3; // ill-formed, right? cannot access
>
> } local;
> }
>
> };
--
alf_DOT_steinbach_AT_ac_DOT_com (clean the address before replying)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: fvali@biotrack.com
Date: 1999/04/14 Raw View
Hi folks, can someone please help me out here and provide some rationale as
to why they believe the following fragment of code contains ill-formed or
well-formed uses of typedef.
thanks in advance.
-fais
Example:
typedef int I;
class Outer
{
// This is an error according to an example (non-normative) in the
// standard [refer to 3.3.6] - but can someone explain exactly why?
typedef I I;
class PrivInner { };
class PrivInner2 { };
class PrivInner3 { };
public:
// can we give the same name public access by redefining it using a
// a typedef but under different access
// refer to 7.1.3 [2]
typedef PrivInner PrivInner;
// can we redeclare Outer using a typedef? refer to 9.2 [13]
// Doesn't this explicitly add a member of type name Outer?
// Yes I know there is an implicit addition of Outer for the purposes
// of name lookup.
typedef Outer Outer;
struct PubInner;
friend struct PubInner;
struct PubInner
{
// Is this an error since we are retypedefining a name
// that has not been originally declared in PubInner's class scope.
typedef PrivInner2 PrivInner2;
};
void memfx()
{
typedef PrivInner2 PrivInner2; // ill-formed or well-formed?
struct
{
PrivInner2 p2; // if above is well-formed so is this, right?
PrivInner3 p3; // ill-formed, right? cannot access
} local;
}
};
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]