Nested classes and accessing nested class functions

I"m trying to instantiate an object of a nested class.
I have a parent class with simple cout which when created using the new object command works well. I'm trying to do the same for the nested class.

How can I
1. Create a nest object using the same way as hen
2. access the display function of the nest class.

I can't seem to figure it out.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  

class hen{
	public:
		hen(){
			cout << "This is the hen constructor" << endl; //constructor
			}
			
		void display() {
			cout << "This is the hen on display" << endl;	// display function for the hen class
		}
		
		~hen(){
			cout << "This is the hen destrucutor" << endl;			//destructor of hen object
		}
		
		
		class nest{
			public:				
				nest(){
					cout << "This is the constructor of the nest class" << endl;  //nest class constructor					
				}
				
				display(){
					cout << "This is the nest class on display" << endl;		//display function for nest class
				}
				
				~nest (){
					cout << "This is the nest class destructor" << endl;  	//nest class destructor
				}
							
		
		};
		
			
		
	};

		

int main()
{
	hen *henObject;      // this works ok
	henObject = new hen();	//works ok
	 henObject->display(); //works ok
	
	
	hen::nest nestObject;	//works ok, but would like to initiate the same as above. 
	nestObject.display();	
	
	delete henObject;
	delete nest::nestObject;
	
	
	
	
	
}
1
2
auto nestObject = new hen::nest();
nestObject->display();
Topic archived. No new replies allowed.