I have a class here that contain linked list of other class cars example
class transportation
{
private;
int id;
list <car> *cars;
int keyval;
public :
set()
{
}
void setTransportation(int ids, list <car> *carss, int keyvals)
{
id=ids;
cars[keyvals]=carss[keyvals];
keyval=keyvals;
}
list <car> *getCars()
{
return cars; // I have to accessed cars list to be modified in my main
// is this how I do it ?????
}
above is only a excerpt from my code. What I have to do is to set list of cars in the main, thus I will call setTransportation in main and pass in list of carss to build up the linked list of car. Am i doing the right thing on setTransportation? As i have to dynamically allocated memory to array of list cars, how do I do that in my main function?
int main()
{
car bmw;
transportation *ptr=new transportation;
list <car> carList[100];
list <transportation> transportationList;
//other code
if (i == 0) {
bmw.setCar(iseq,type);
carList[k].push_back(bmw);
list <car> *inputList = (*ptr).getCars(); // is this how I accessed list from
inputList[k]=new list <car> [k]; // list class???
(*ptr).setTransportation(iid,carList,k);
transportationList.push_back((*ptr));
k++;
}
Any help will be appreciated