Hi,
I am trying to create a doubly linked list and was hoping for some advice on if my classes are correctly declared.
My classes are '3 deep' as shown in the attached image. I want to hold all the objects from all the classes within a single doubly linked list.Code:class Car { public: AddaNewDieselHardTop();//All functions for adding new nodes declared here in Car. This is OK because they are Friend Classes? AddaNewDiesleSoftTop(); private: CarNode *head; }; //////////////////////////////// class Diesel { friend class Car; }; /////////////////////////////// class DieselHardTop { friend class Diesel; friend class Car; private: int MPG; DieselHardTop *llink, *rlink; }; class DieselSoftTop { friend class Diesel; friend class Car; private: int MPG; DieselSoftTop *llink, *rlink; };
The user will be able to add new instances of DieselHardTop and DieselSoftTop, and I'm wondering if I can declare the 'AddNewDieselHardTop()' and 'AddNewDieselSoftTop' functions just once within the Car class declaration, or if I would need to declare these functions in their own respective classes.
The user will select 'Add a new car' from a menu, and I was going to use a Switch statement, so if the user chose to 'Add a new DieselSoftTop', I would then call that function, which if correct, would be declared within Car, and not the DieselSoftTop class.
Hope that makes sense!
Many thanks!!!



LinkBack URL
About LinkBacks



