Forward declaration of a nested class

后端 未结 1 1648
南方客
南方客 2021-01-28 14:32

I am trying to forward delcare this nested class, I already tried it but i didnt work. When i try to forward declare i get cant acces private member errors, so I guess i am doin

相关标签:
1条回答
  • 2021-01-28 15:07

    The nested type is part of the enclosing type. That means that it cannot be forward declared by itself, but it can be declared in the definition of the enclosing type, and then defined outside:

    class enclosing {
       class inner;          // Forward declaration
    };
    // Somewhere else
    class enclosing::inner { // Definition
       int x;
    };
    

    What you cannot do is forward declare the inner type outside of the definition of the enclosing type:

    class enclosing::outer;  // Error
    
    0 讨论(0)
提交回复
热议问题