Matthias said:
That's not entirely true -- consider the following example:
class Outer {
typedef int T;
public:
class Inner {
T x;
};
};
this could be extended to object relationship (not just types).
I wonder how. Instances don't have scopes. Members don't exist
without instances. Here, you have 'T' which is a name that can be
looked up at the compilation time, and the scope of 'Outer::Inner'
has a very specific set of rules for name lookup.
Now, remove they 'typedef' (to make 'T' an instance). What do you
have?
class Outer {
int T;
public:
class Inner {
void foo() { T = 42; }
};
};
You have 'T' that is an instance of 'int', but it doesn't exist
in a vacuum. It only exists in an instance of 'Outer'. The
compiler has no idea where that instance of 'Outer' is. No clue
whatsoever. What do you propose? Let's rehearse the conversation
you're going to have in 'comp.std.c++' (see my suggestion below).
You're saying that if you declare an instance of 'inner' inside
an instance of 'Outer', the compiler has to know how to get the
address of one and convert it to the address of the other. How?
What if it doesn't exist?
class Outer {
int T;
class Inner {
void foo() { T = 42; }
} inner;
void bar();
};
void Outer::bar() {
Inner i;
i.foo(); // now what?! Whose 'T' are we changing now?
}
Are you going to prohibit the use of 'Inner' like that? Fine,
somehow 'Inner' is private (as I made it in my last example), but
it should also become incomplete class (so you cannot instantiate
it as a stand-alone object even inside 'Outer' scope)? Then how
do we instantiate the 'Outer::inner' member? See the conflict?
Or do we simply allow 'i' inside 'Outer::bar' to change 'this->T'
somehow?
Think about all possible variations of the use of 'Inner' and not
just how _you_ want to use it. I believe the expression is "to
see beyond one's nose".
In this case it would be the behaviour I want; certainly far from
"nonsense".
But you seem to want to have this behaviour as the norm. It's not
because it cannot be. It just wouldn't make sense as the norm.
It's impossible to make everybody happy, that's true. That's why
the langauges are usually designed to make the majority of people
happy and if a few unhappy people remain, they usually get to use
the work-arounds.
"Inner" doesn't; but the compiler does.
So? The compiler knows many other things. Every compiler knows
its own set of things, AAMOF. If you need to be able to know the
things the compiler knows, turn to the compiler's manual. If you
want to make what compiler knows available to the programmer and
specify that in the Standard, then it's a different story.
I believe you're arguing a change in the language. I don't think
this is the right newsgroup for it. Try 'comp.std.c++'. Explain
what you think is missing from the language, make a proposal. Do
not forget to have a business case (what problem it solves that
cannot be solved otherwise). Then present your argument and have
the language changed. Or have your mind changed for the work-
around that you're "trying to avoid". Either way, 'comp.std.c++'
is _the_ newsgroup for trying to get your point across to the
people who are on the bleeding edge of making C++ work better.
V