tags:

views:

72

answers:

2

I have question with this same title here but now as I'll present in code below this seems to behave in the opposite way to the way explained to me in my first question with the same title. Ok code:

class LINT_rep
{
private:
    char* my_data_; //stores separately every single digit from a number
public:
    class Iterator:public iterator<bidirectional_operator_tag,char>
        {
private: 
char* myData_
public:
        Iterator(const LINT_rep&);
    };
};

#include "StdAfx.h"
#include "LINT_rep.h"


LINT_rep::Iterator::Iterator(const LINT_rep& owner):myData_(nullptr)
{
    myData_ = owner.my_data_; /*
        HERE I'M ACCESSING my_data WHICH IS PRIVATE AND THIS   
        CODE COMPILES ON VS2010 ULTIMATE BUT IT SHOULDN'T  
        BECAUSE my_data IS PRIVATE AND OTHER CLASS SHOULDN'T  
        HAVE ACCESS TO IT'S PRIVATE MEMB. AS EXPLAINED TO ME IN  
        QUESTION TO WHICH I;VE PROVIDED LINK. */
}

Question in the code. Thanks.

+1  A: 

According to the standard 11.8 a nested class is a member and as a member it has the same rights as the rest of the class members, so it can access private members.

11.8 Nested classes [class.access.nest]
1- A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules (clause 11) shall be obeyed.

Arkaitz Jimenez
@Arkaitz so why in my previous question with this same title people were giving the very opposite answers? And which standard are you citing?
There is nothing we can do
C++ standard, n1905 draft from 2005
Arkaitz Jimenez
You're misunderstanding the answers to your previous question. Go read the accepted answer to that question again.
SoapBox
That's from the draft for C++0x, which isn't a standard yet. In the current standard, is says "The members of a nested class have no special access to members of an enclosing class".
Mike Seymour
The draft for C++0x is N3092
Arkaitz Jimenez
@SoapBox I do understand the answer. I think you do not understand my question. The other answer was valid because older standard say that inner class has no special rights and new standard says the opposite.
There is nothing we can do
+5  A: 

Access rights for nested classes to members of the enclosing classes are changing in the upcoming C++0x standard. In the current standard, 11.8 says:

The members of a nested class have no special access to members of an enclosing class

In the draft for C++0x, this changes to

A nested class is a member and as such has the same access rights as any other member

Some compilers are adopting the new access rules; from your question, I guess VS2010 does, and I know from experience that GCC has done for some time.

Mike Seymour