Objects of Other Classes as Class Data Members


In a previous lecture you saw that in C++ it is possible to construct nested structures. In C++ it is also possible to nest one class within another.

 Note:  Some authors only call classes or structures nested if one of the classes is defined entirely within the other. However in these notes the term: nested classes shall be used when an object of one class or structure is an attribute of another class. Some authors use the term composition of classes when an object of one class is an attribute of another. The example invclass.cpp has one class Date nested within the class Invoice.

Notice in this example what is required to initialize the attributes and use the methods in the inner most class. When using nested classes, one must guard against making the resulting class too complicated. Many times the nesting of classes defeats the philosophy of C++ which creates classes and then overburdens the program with the interlocking class constructs. When this happens, it may be too difficult to know how the system works.




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net