Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13326
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Typedef of inaccessible type |
| Date | 2012-01-13 15:07 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <jepds4$tth$1@dont-email.me> (permalink) |
| References | <29510730.1476.1326458883399.JavaMail.geo-discussion-forums@yqni15> |
On 13.01.2012 13:48, ales.pergl@gmail.com wrote:
> When I have multiple nested classes, I find it unnecessarily verbose to spell out the fully qualified name of the most nested class when defining its members.
> So I'm looking for a way to define an alias for the fully qualified class name. Like this:
>
> // in header
> class A {
> class B {
> class C {
> void DoStuff();
> };
> };
> };
You can always replace nested classes with friendships etc.
I suggest you try that.
To see what the above really means.
> // in cpp
> typedef A::B::C C; // error, A::B::C is inacessible in this context
But if you make it accessible in some way, then you would be breaking
the rules you have elaborately set up with the class nesting.
> void C::DoStuff() {} // would love to be able to shorten the class name
>
> The problem is, the above doesn't compile, because C is not accessible from
> global scope. The easiest workaround is to define a macro instead of a typedef:
>
> #define C A::B::C
>
> Does anybody know of a better way, without using the preprocessor?
You can always confer friendship to some class that can then provide
typedefs.
But then you would be exposing what you have gone to pains to make
inacessible.
There's nothing wrong with using the preprocessor in a sensible way,
like in your case, with the effect confined within a separately compiled
file.
Cheers & hth.,
- Alf
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Typedef of inaccessible type ales.pergl@gmail.com - 2012-01-13 04:48 -0800
Re: Typedef of inaccessible type "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-13 15:07 +0100
Re: Typedef of inaccessible type ales.pergl@gmail.com - 2012-01-13 07:00 -0800
Re: Typedef of inaccessible type "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-13 16:52 +0100
Re: Typedef of inaccessible type ales.pergl@gmail.com - 2012-01-16 07:19 -0800
Re: Typedef of inaccessible type jgk@panix.com (Joe keane) - 2012-01-16 16:13 +0000
Re: Typedef of inaccessible type Markku Linnoskivi <markku.linnoskivi@gmail.com> - 2012-01-13 06:09 -0800
Re: Typedef of inaccessible type Victor Bazarov <v.bazarov@comcast.invalid> - 2012-01-13 10:54 -0500
Re: Typedef of inaccessible type Leigh Johnston <leigh@i42.co.uk> - 2012-01-13 14:32 +0000
Re: Typedef of inaccessible type Leigh Johnston <leigh@i42.co.uk> - 2012-01-13 14:38 +0000
Re: Typedef of inaccessible type "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-13 15:46 +0100
Re: Typedef of inaccessible type Leigh Johnston <leigh@i42.co.uk> - 2012-01-13 14:53 +0000
Re: Typedef of inaccessible type ales.pergl@gmail.com - 2012-01-13 06:42 -0800
Re: Typedef of inaccessible type Leigh Johnston <leigh@i42.co.uk> - 2012-01-13 15:04 +0000
Re: Typedef of inaccessible type Leigh Johnston <leigh@i42.co.uk> - 2012-01-13 15:19 +0000
csiph-web