Question: I have a class Outer with a nested class Inner. Inner has a method 'print' which tries to access a data member of class Outer. The code compiles fine but I get a segmentation fault error when I try to run the programme. 

```
#include <iostream>

class Outer{
public:
  Outer();
  ~Outer();

  class Inner{
  public:
    Inner(Outer *parent){}
    void print(){std::cout<< parent-> data <<std::endl;}
  private:
    Outer *parent;
  };
  Inner *obj;

private:
  int data;
};

Outer::Outer(): data(99), obj(new Inner(this)){}
Outer::~Outer(){delete obj;}

int main(){
  Outer outer;
  outer.obj->print();
  return 0;
}

```

I'm not sure what is the issue as I have already passed the 'this' pointer to the inner object.

The code is compiled with g++4.8.2 using the c++11 flag.

Answer: 
You are not storing the pointer to the `Outer` class in the `Inner` constructor:

```
Inner(Outer *parent) : parent(parent) {}

```

Also, if you use C++11, this may be a good case to use smart pointers.
You are not doing anything with `parent` in

```
Inner(Outer *parent){}

```

You need to `Inner`s `parent` member in the constructor

```
Inner(Outer *parent_) : parent(parent_){}

```