Thanks guys! I like the idea of making the display() a little more interesting. I'm reading up more on the relationships and purposes of nested classes. Trying to show how they are related in the program, I haven't yet come up with the idea, but I'll keep going at it.
I have to create a Hen class, and inside that a Nest class, and inside that an Egg class. Each has a display() function, and each has a constructor and destructor that displays a message when called. In main() I have to create an instance of each using new, call the display, then free the storage using delete (hence the dynamic memory allocation).
I think I got this all right. But I can't begin to think of how to properly test it.
the problem I have is that the assignment is not showing any porpuse of nesting. there are no relationships between the classes, you just write Hen::Nest::Egg instead of hen_egg.
compare against map::iterator to operate on `map' or list::node (hidden) to construct a `list'
Ok, so I have made these changes, but I want to make sure I understand nested classes.
1 2 3
removed. figured things out.
}
What I would like to do is change the two bolded lines to somehow reference that is a nested class in the display() function. I don't know if this is possible with nested classes alone though. When I try, I get errors:
1 2 3 4 5 6
In member function 'void Hen::Nest::display()':
error: invalid use of non-static data member 'Hen::henName'
cout << Hen::henName <<" lives in nest number " << nestID << "!\n"; // class Nest display() function
^~~~~~~
note: declared here
string henName; // name of Hen
Which i believe is telling me that my object hen1, can't pass it's name to the display() function in the new object nest1. And that makes sense as there is nowhere in the code that seems to reference each other.