Key word class before class-member



  • Is the key word counted class Before class-member, as a kind of forward declaration of class, so the compiler doesn't care what the identifier is.


    Are these code fragments identified?

    class Foo
    {
    private:
        class Bar* a;
    };  
    

    and

    class Bar;
    class Foo
    {
    private:
        Bar* a;
    };
    


  • Yes, they are.

    According to the http://eel.is/c++draft/basic.scope.pdecl#7 [basic.scope.pdecl]
    for such announcements as elaborated-type-specifierthe name is declared in the external sphere of visibility.

    This can be demonstrated by this code:

    struct Foo {
        struct Bar* a;
    };
    

    struct Bar {};

    int main() {
    Bar b;
    Foo f;
    f.a = &b;
    }

    However, for the declaration of the species class name;the name is declared in the same area of visibility, for example

    struct Foo {
    struct Bar;
    };

    struct Foo::Bar {};


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2