C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 8th, 2006, 05:09 AM
bill21 bill21 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 1 bill21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 48 sec
Reputation Power: 0
Please help me to do my homework!!!

I have constructed this 4 classes: creature,good_creature,bad_creature,creature_socie ty.
Especially the creature_society class is this:

Code:
class creature_society {
     public:
        int N;
        creature* plasma;
        int M,L,good_thrsh,bad_thrsh;
     public:
        creature_society(int,int,int,int,int);
        ~creature_society();
        int beat_cr(int);
        int bless_cr(int);
        int clone_next(int);
        int clone_zobies(int);
        int no_of_good();
        int no_of_zobies();    
            
};

And this is the constructor

creature_society::creature_society(int a,int b,int c,int d,int e) {
int k,epilogi,f;
long curtime;

N=a;
M=b;
L=c;
good_thrsh=d;
bad_thrsh=e;
curtime=time(NULL);
srand((unsigned int) curtime);
creature *plasma = new creature[N];
for(k=0;k<=N-1;k++) {
epilogi=(rand()%2)+1;
if (epilogi==1) {
    f=rand()%42;
    plasma[k] = good_creature(L,k,good_names[f]); 
    }
else {
    f=rand()%54;
    plasma[k] = bad_creature(L ,k,bad_names[f]); 
    }
}
cout<<"\nA creature society has been constructed\n"<<endl;
}


The main problem is when i try to access my functions from a function of the class creature_society i have problem
For example if i do cout<<plasma[2].name<<endl; inside the constructor of creature_society there is no problem.
But if i do the same think inside the function beat_cr(int); of creature society it is problem.
nothing appears but a SEGMENTATIOJN FAULT!!
What i must do? I think that i don't have access to my array which i creat in the constructor of creature_society. How can i do it?

Last edited by B-Con : April 8th, 2006 at 09:44 PM. Reason: added [code] tags

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Please help me to do my homework!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT