10

I have this simple code:

#include <vector>

class A
{
    private:
        struct B{int x;};
    public:
        std::vector<B> v;
};

int main()
{
    A a;

    for (std::vector<A::B>::iterator it = a.v.begin(); it != a.v.end(); ++it)
    {
        it->x = 0;
    }
    for (auto it = a.v.begin(); it != a.v.end(); ++it)
    {
        it->x = 0;
    }
}

As expected I have build error in the first for loop - A::B is private, but second for loop compiles fine in Visual Studio 2010, 2012 and 2013. Is this normal behavior or it's a bug in the compiler?

Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
  • 5
    It is correct. It has been discussed here before. I'll try to find it. Edit: http://stackoverflow.com/q/13532784/1171191 The short of it is that `private` applies to the *name*, not the *type*. – BoBTFish Dec 10 '13 at 13:28

0 Answers0