#include
class Outer
{
int o;
public:
void setOuter(int o)
{
this->o=o;
}
class Inner
{
public:
int i;
Inner
is just a class defined at a different scope. It's no different than saying
class Inner
{
public:
int i;
int retOuter(Outer *obj)
{
return obj->o;
}
};
and then
Inner::i =50
which obviously isn't possible because i
isn't static
.
Declaring an inner class doesn't automagically declare a member of that type for the outer class which you can access using that syntax.
Now, something like:
class Outer
{
int o;
public:
void setOuter(int o)
{
this->o=o;
}
class Inner
{
public:
int i;
int retOuter(Outer *obj)
{
return obj->o;
}
} innerMember;
// ^^^
// declare a member
};
int main(int argc, char **argv) {
Outer *obj1=new Outer;
obj1->innerMember.i =50; //Access the inner class members by Outer class object!
}
would work.