Nested or Inner Class Example in C++


This code declares a class Outer that contains another nested class Inner. The Inner class has a member function display() that simply prints "Display Inner :" to the console. In the Outer class, there is a member function fun() which simply calls the display() function of the member object i of the Inner class.

In the main() function, an object of Inner class is created using the scope resolution operator :: and stored in the variable i. However, this object is not actually used and the program simply exits without performing any operations. Therefore, the code doesn't really do anything useful and can be considered incomplete.

Source Code

#include<iostream> //Doubt
using namespace std;
class Outer
{
public :
    void fun()
    {
        i.dispaly();
    }
    class Inner
    {
    public:
        void dispaly()
        {
            cout<<" Display Inner :"<<endl;
        }
    };
    Inner i;
};
int main()
{
    Outer :: Inner i;
    return 0;
}
To download raw file Click Here

Output

Display Inner

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples