C++ - Accessing private, nested iterator
<p>I can't figure out how to solve this problem. My iterator constructors need to be private, so I use the container to return an iterator, but it refuses to compile.</p>

<p>A.h</p>

<pre><code>class A {
    public:
        class iterator {
            friend class A;
            public:
                virtual ~iterator();
                iterator operator++(int);
                iterator operator--(int);

            private:
                iterator(int index, A container);
        };


        iterator begin();
        iterator end();

};
</code></pre>

<p>A.cpp</p>

<pre><code>A::iterator A::begin(){
    return iterator(0, *this);
}

A::iterator A::end(){
    return iterator(length(), *this);
}
</code></pre>

<p>I then call it like this:</p>

<pre><code>for(A::iterator i = a.begin(); i != a.end(); i++)
    std::cout &lt;&lt; *i;
</code></pre>

<p>But that last block says that "A::iterator is private within this context". I have a feeling the iterator constructor is only being called outside of begin(), but I don't know how to fix it. I'm fairly new to C++, so any help would be appreciated!</p>
