
April 8th, 2006, 05:09 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 1
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
|