Inner class : class definition « Class « C++ Tutorial






#include <iostream>
using namespace std;
class Outer 
{
 public:
   Outer(void) 
   { cout << "Just instantiated an outer\n"; 
     outer_data = 2002; 
   };
   class Inner 
   {
     public:
       Inner(void) 
     { 
       cout << "Just instantiated an inner\n"; 
           inner_data = 1001; 
     };
       void show_data(void) { cout << "Inner: " << inner_data << endl; };
     private:
       int inner_data;
   } inside_stuff; 
   void show_all_data(void) 
   { 
     inside_stuff.show_data(); 
       cout << "Outer: " << outer_data << endl; 
   };
 private:
   int outer_data;
};

int main(void)
{
   Outer my_data;
   my_data.show_all_data();
}








9.1.class definition
9.1.1.Define your first class
9.1.2.classes example
9.1.3.Create an object from a Class and call its function
9.1.4.Define a class with a member function that takes a parameter
9.1.5.Define class with a data member and member functions to set and get its value
9.1.6.Instantiating multiple objects of the class using its constructor
9.1.7.Define class to record time
9.1.8.Class objects can be assigned to each other using default memberwise assignment
9.1.9.Local Classes: A class may be defined within a function
9.1.10.containership with employees and degrees
9.1.11.Inner class
9.1.12.Friend Classes