The problem here isn't so much that one thing can't see the other as
that you're trying to change instance members in class definitions.
You create a class definition that defines int a, then a class that
tries to change the instance of int a. The class definition of Foo
doesn't actually contain any int a, just the notion that an object of
the type defined in Foo would have an int a. You'll notice that Mr.
Poblacion's response clearly defines this distinction by instantiating
classes.
Mr. Poblacion's solution should work perfectly for many needs.
Another, one that would serve other needs, would be to define Foo.a as
a static int, in which case Foo.Bar.ChangeA() could modify Foo.a. In
that case, Foo myFoo would contain no definition int a, i.e., there
would be no myFoo.a, just Foo.a.
s}
On Oct 23, 9:41 am, hstagni <sta...@gmail.comwrote:
Here is a sample to explain my problem
class Foo
{
int a;
class Bar
{
void ChangeA()
{
a = 1;
}
}
}
function ChangeA() does not work because 'a' doesn't belong to Bar; it
belongs to Foo. So the question is: how can I make a function inside
class Bar change an element that belongs to Foo?
This could be possible cause(in my program) each object of kind Foo
has inside it at least one object of kind Bar and this object have to
change his 'parent' object.