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.
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;
}