P
ppavlo
Hello all,
I have class of such tye
class Manager {
public:
static Manager* getInstance();
Worker* getWorker(char* name);
private:
Manager(...);
Worker** workers;
int numberOfWorkers;
static Manager* instance;
};
It is sort of singleton implementation. First call to getInstatnce()
calls Manager() constructor which creates dynamically the workers array
of pointers to Worker objects and asignes to numberOfWorkers size of
that array. getWorker() method searches the proper worker by the name
in the workers array, if there is no such worker it looks to specific
file that may have the needed record, then It takes from that file
creates the new Worker object, and returns the worker to user, but I
also want to append this worker to existing array, So I'm creating new
array of pointers bigger than previous, write all pointers from old
array to new, and also that new worker that was created from file's
record. Then I want to delete the old "Worker** workers" pointer. So
when aplying delete to that pointer I'm having Segmentation Fault
error. Can anybody suggest me possible troubles that I'm getting into?
I'll appreciate any answers. If something is not cleare please ask.
I have class of such tye
class Manager {
public:
static Manager* getInstance();
Worker* getWorker(char* name);
private:
Manager(...);
Worker** workers;
int numberOfWorkers;
static Manager* instance;
};
It is sort of singleton implementation. First call to getInstatnce()
calls Manager() constructor which creates dynamically the workers array
of pointers to Worker objects and asignes to numberOfWorkers size of
that array. getWorker() method searches the proper worker by the name
in the workers array, if there is no such worker it looks to specific
file that may have the needed record, then It takes from that file
creates the new Worker object, and returns the worker to user, but I
also want to append this worker to existing array, So I'm creating new
array of pointers bigger than previous, write all pointers from old
array to new, and also that new worker that was created from file's
record. Then I want to delete the old "Worker** workers" pointer. So
when aplying delete to that pointer I'm having Segmentation Fault
error. Can anybody suggest me possible troubles that I'm getting into?
I'll appreciate any answers. If something is not cleare please ask.