[prog] C++ STL Problem
Noir
acknak_haflife at yahoo.co.uk
Sun Oct 24 04:02:36 EST 2004
I am working on a Aeroplane.cpp file where it asks to "make a PassengerList
supported by GenericList template." I am utterly confused as to what I
should do in regards to this. I have made my cpp file which also asks me to
make a custom constructor, a copy constructor to perform deep copy, a
destructor and a display method (I think I have done all these). The only
problem is with the GenericList template.
//Aeroplane.h
#include "TemplateList.h"
typedef GenericList <Passenger,5>PassengerList;
typedef GenericList <Luggage,20>LuggageList;
using namespace std;
class Aeroplane
{
private:
string fBrand;
string fModel;
PassengerList *myPassengers;
LuggageList *myLuggage;
public:
Aeroplane(const string Brand, const string Model,
PassengerList *Passengers, LuggageList *Luggage);
Aeroplane(const Aeroplane& src);
~Aeroplane();
void Display();
};
#endif // AEROPLANE_H
//Aeroplane.cpp
#include <string>
#include "Aeroplane.h"
using namespace std;
Aeroplane::Aeroplane (const string Brand, const string Model, PassengerList
*Passengers,
LuggageList *Luggage) {
this->myPassengers = new PassengerList (*Passengers);
this->myLuggage = new LuggageList (*Luggage);
}
Aeroplane::Aeroplane (const Aeroplane& src) : fbrand(src.fBrand),
fModel(src.fModel) {
this->myPassengers = new PassengerList (*src.myPassengers);
//might cause problem later. If so, comment out+compile and see
this->myLuggage = new LuggageList (*src.myLuggage);
}
Aeroplane::~Aeroplane()
{
delete this->myPassengers;
delete this->myLuggage;
}
void Aeroplane::Display()
{
cout << this->fBrand << "" << this->fModel <<endl;
// myPassengers->Display;
myLuggage->Display;
}
More information about the Programming
mailing list