Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #13337

Re: Typedef of inaccessible type

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: Typedef of inaccessible type
Date 2012-01-13 10:54 -0500
Organization A noiseless patient Spider
Message-ID <jepk4h$3da$1@dont-email.me> (permalink)
References <29510730.1476.1326458883399.JavaMail.geo-discussion-forums@yqni15> <e5e4b9fa-8619-4548-9e86-9987b5b99129@t30g2000vbx.googlegroups.com>

Show all headers | View raw


On 1/13/2012 9:09 AM, Markku Linnoskivi wrote:
> On 13 tammi, 14:48, ales.pe...@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();
>>        };
>>      };
>>    };
>>
>>    // in cpp
>>    typedef A::B::C C;   // error, A::B::C is inacessible in this context
>>
>>    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?
>>
>> Thanks.
>
>
> The class default visibility is private, so the classes B and C are
> not accessible from out side, even if you give the fully qualified
> name. So define the classes in public visibility and the typedef
> works. And DO NOT use a define like that! That will replace all
> occurances of capital C

No, only occurrences where C is a complete token.  For instance, in the 
token Class, the 'C' is not going to be replaced to yield A::B::Class.

 > with the given string and cause all kinds of
> hard to understand errors.

I am fairly certain that the OP doesn't have real classes named A, B and 
C...

V
-- 
I do not respond to top-posted replies, please don't ask

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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