pointers to pointer array

1
2
3
4
5
6
7
8
9
10
11
void StringofCars::push(Car more)
{
    cout <<"11"<< more.carNumber << more.destination << more.kind << more.loaded << more.reportingMark << endl;
    Car* newcar;
    newcar = new Car(more);
    cout << "22" << newcar->carNumber << newcar->destination<< newcar->kind << newcar->loaded << newcar->reportingMark << endl;
    point[size] = newcar;
    ++ size;
    cout << "33" << point[size]->carNumber << point[size]->destination<< point[size]->kind << point[size]->loaded << point[size]->reportingMark << endl;
    delete newcar;
}

// output on the screen //

11819481NONEmaintenancefalseCN
22819481NONEmaintenancefalseCN
334001536
//////////////////////////////
so right now i have two classes. one is car and one is arrayofcars
car object has elements such as number kind loaded reportingmark and destination.
array point [] is a pointer to a pointer to a car
so Car ** point = new point [10];
the problem here is when i put in the pointer of a car object into array of pointers of car.
the value changes and gives error as you see
any ideas?
in line 7 you put pointer into point [size].
After it you increment size.
So in line 9 you try to read from other (next) array element.
Good catch! thanks :)
Topic archived. No new replies allowed.