Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          nested-classes/nested-3a.cpp - Problems solved - This program compiles.Lecture 5 - slide 12 : 40
Program 5

// For exercise.
// Inspired from page 851 of "The C++ Programming Language", 3ed version.
// Accessing private_i and public_i as instance variables in Outer via a parameter.


#include <iostream>
#include <string>

class Outer{
private:
  int private_i;

public:
  int public_i;

  class Inner{
  public:
    void fi(Outer *p);
  };

};

void Outer::Inner::fi(Outer *p){
  int local1 = p->private_i * 2;       // OK
  int local2 = p->public_i * 3;        // OK

  std::cout << local1 << ", " << local2 << std::endl; 
}


int main(){
  Outer o;  
  Outer::Inner i;

  i.fi(&o);
}