Access to private data type of an outer class from inner class

Discussion in 'C++' started by agentprog@gmail.com, Apr 2, 2013.

  1. Guest

    Hello!

    I have a container class, its structure is implemented using private structure. And i would like to implement something like iterator and it should be able to have a pointer to that private structure.

    class Container {
    public:
    // ...
    class Iterator {
    // ...
    private:
    //Container::node *ptr;
    node *ptr;
    };
    private:
    struct node {
    // ...
    };
    // ...
    };

    Compiler does not allow me to do that even if Iterator is a friend of Container.
    Is there a way to access Container::node from Container::Iterator or maybe i should rethink the whole design?

    If it makes sense, i use g++ (4.6.3) as a compiler in c++03 standard mode.
    , Apr 2, 2013
    #1
    1. Advertising

  2. Stefan Ram Guest

    writes:
    >Is there a way to access Container::node from Container::Iterator or maybe i should rethink the whole design?


    You need a forward declaration.

    class Container { private: struct alpha; /* :forward declaration */
    public: class Iterator{ ::Container::alpha *p; }; private: struct alpha {}; };
    int main(){}
    Stefan Ram, Apr 2, 2013
    #2
    1. Advertising

  3. Guest

    That was really a silly mistake of mine, thank you very much!
    , Apr 2, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lonelyplanet999

    Access outer / inner class variables query

    lonelyplanet999, Nov 11, 2003, in forum: Java
    Replies:
    3
    Views:
    5,284
    lonelyplanet999
    Nov 18, 2003
  2. Yamin
    Replies:
    4
    Views:
    16,664
    Yamin
    Oct 24, 2004
  3. Ahan Hsieh
    Replies:
    2
    Views:
    565
    Ahan Hsieh
    Oct 5, 2007
  4. Qi
    Replies:
    4
    Views:
    751
  5. John Gordon
    Replies:
    5
    Views:
    434
    Adam Skutt
    May 9, 2012
Loading...

Share This Page