Alright what I have done is implemented a standard linked list class in C++ called Targets which contains holds the list of objects called target.
That part is not a problem and everything seems to work find when I create a Targets object in main and add and delete targets.
Then I created another class that is basically just to separate some of the source code into section. So that class is called my Tracker class which contains the Targets linked list object. But in that class I need to keep an array of 10 linked list objects.
During the initialization of the Tracker class create the Targets objects like:
for(int i=0;i<TRACK_LEN ;i++){
allTargets[i] = new Targets();
}
and allTargets[] is defined in the header file like:
Targets* allTargets[TRACK_LEN];
The Problem is when I go to use the a Targets object from the allTargets[] I get a seg fault. from using the allTargets object like:
allTargets[0]->count();
I can fix it if I reinitialize the Targets object before I use it like:
allTargets[0] = new Targets();
allTargets[0]->count();
but that will delete my data so that wont work, any ideas?
That part is not a problem and everything seems to work find when I create a Targets object in main and add and delete targets.
Then I created another class that is basically just to separate some of the source code into section. So that class is called my Tracker class which contains the Targets linked list object. But in that class I need to keep an array of 10 linked list objects.
During the initialization of the Tracker class create the Targets objects like:
for(int i=0;i<TRACK_LEN ;i++){
allTargets[i] = new Targets();
}
and allTargets[] is defined in the header file like:
Targets* allTargets[TRACK_LEN];
The Problem is when I go to use the a Targets object from the allTargets[] I get a seg fault. from using the allTargets object like:
allTargets[0]->count();
I can fix it if I reinitialize the Targets object before I use it like:
allTargets[0] = new Targets();
allTargets[0]->count();
but that will delete my data so that wont work, any ideas?
Comment