LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-03-2002, 10:41 PM   #1
tristan_vdv
LQ Newbie
 
Registered: Nov 2001
Location: Australia
Distribution: RH 7.2
Posts: 17

Rep: Reputation: 0
C++ dynamic classes


Hi,
I've tried using a dynamic class of arrays and I'm obviously not doing things right b/c after a while my program always segment faults

first of all i have a pointer class
myclass *cur;
myclass *array

cur=myfunc(); (my myfunc below)

<resize my class array with malloc/realloc>

array[last_item]=*cur;

myclass* myfunc()
{
myclass *con;
con = new myclass()
return con;
}

all this seems to work until after a while i get a seg fault so i am doing somethign wrong.

this is the line that causes the seg fault, but its not untill bout the 4-7 time.
array[last_item]=*cur;

should i be moving the class over wiht memcpy or something? or i am doing this whole thing totaly wrong?

Thanks
Tristan
 
Old 01-04-2002, 04:30 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
If you are gonna have an array of pointers, then maybe you should define the array as:

myclass **array;

And it seems like you are using malloc and new. Just make sure you don't mix the two up and start doing a delete on something you've allocated with malloc. Better to just use new and delete.

As far as I can see your only storing the pointers in the array so a memcpy wouldn't really be necessary.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Classes in VC++ Diederick Programming 2 11-30-2005 10:57 AM
Possible uses for classes. RHLinuxGUY Programming 4 11-21-2005 10:10 PM
classes in C++ niteshadw Programming 2 07-05-2005 07:05 PM
OOP (PHP) classes and extended classes ldp Programming 3 03-05-2005 11:45 AM
Dynamic name resolution for dynamic IP merlin740 Linux - Software 2 10-04-2004 05:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration