Nested Classes in C++ A Stack Class Inner Class Types Benefits of Inner Classes
| |
What are Inner Classes?
An inner class is one that is defined within another class.
Why is this good thing? Here are some reasons:
- An inner class can make clear an explicit relationship with the enclosing
class.
- An inner class can be hidden within the enclosing class. (Data
hiding/encapsulation.)
- Certain kinds of inner classes can access all the fields and methods
within the enclosing class, which can be very helpful.
The bottom line is that using inner classes can lead to more readable, more
maintainable, and more reliable code.
|