473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with delete

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.

Jan 3 '06 #1
4 1064
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ppavlo wrote:
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;
};
Better use std::string and std::deque or std::list in this case.

<snip> 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
std::deque or std::list would do all this work :)
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.


Well how do you create this array (Code) and how to you try to resize it
(Code)?

- --
Greetings, Thomas Jakob
quicix (at) gmail (dot) com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)

iD8DBQFDunk6KzGu1S9H/nsRAjMJAJ0UL8kWkve087Eb8FjIAJkm8kQ4dQCfVfxO
4oVhcbpoTxHbtBTQYvkyMSE=
=UAc0
-----END PGP SIGNATURE-----
Jan 3 '06 #2

ppavlo escreveu:
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.


Jan 3 '06 #3

Thomas Jakob wrote:

[snip]
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


std::deque or std::list would do all this work :)


I believe a std::map<std::string, Worker> or std::map<std::string,
Worker *> would solve it better.

[snip]

HTH,

Marcelo Pinto

Jan 3 '06 #4

Marcelo Pinto wrote:
I believe a std::map<std::string, Worker> or std::map<std::string,
Worker *> would solve it better.

HTH,

Marcelo Pinto


If Worker is not a trivially copyable class (i.e. could be a base class
or has pointers etc) then the best solution would be std::map<
std::string, boost::shared_ptr< Worker > >
(or another shared_ptr implementation if you prefer).

Jan 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michael | last post by:
Gotta post because this is driving me nuts. Trying to DELETE orphans. I can successfully: SELECT GroupID FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID IS NULL; but when I...
6
by: Matan Nassau | last post by:
Hello. i have a composite which i want to delete. this is a composite which represents a boolean expression (see a previous post of mine with more details at...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
14
by: placid | last post by:
Hi all, i have this struct for a binary tree node typedef struct treenode { char *word; struct treenode *right; struct treenode *left; }TreeNode;
5
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
6
by: Lighter | last post by:
Big Problem! How to overload operator delete? According to C++ standard, "A deallocation function can have more than one parameter."(see 3.7.3.2); however, I don't know how to use an overloaded...
1
by: Rebecca Tsukalas | last post by:
Hello, I have a problem concerning removeChild. This is the XML structure I use with php: <xml_thing <language1 <site>bla1</site <site>bla2</site <site>bla3</site </language1
2
by: Martin | last post by:
Hi all, This is the situation... DatagridView Control with datasource set to datatable. I want the user to be able to delete x number of rows by selecting a row with mouse then clicking a...
2
by: dean.cochrane | last post by:
I have inherited a large application. I have a table which contains a hierarchy, like this CREATE TABLE sample_table( sample_id int NOT NULL parent_sample_id int NOT NULL ....lots of other...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.