i have a problem, i think it has to do with heap memory. would appreciate help.
this is in tribe header:
Survivor* SurvivorsArray = new Survivor[MaxSurvivorsInTribe];
it's my problem. when i write
Survivor* SurvivorsArray = new Survivor[MaxSurvivorsInTribe];
i get this problem:
EXE3.exe has triggered a breakpoint.
this is take my in code to:
if (_crtheap == 0) {
#if !defined (_CRT_APP) || defined (_DEBUG)
_FF_MSGBANNER(); /* write run-time error banner */
_NMSG_WRITE(_RT_CRT_NOTINIT); /* write message */
#endif /* !defined (_CRT_APP) || defined (_DEBUG) */
__crtExitProcess(255); /* normally _exit(255) */
}
return HeapAlloc(_crtheap, 0, size ? size : 1);
}
but if i write:
Survivor* SurvivorsArray = new Survivor[100];
so it's work without error.
Currently it only works if I set up a preset array but if I want to get the array size from the user I get an error.
main:
#include <iostream>
#include <string>
using namespace std;
#include "survivor.h"
#include "tribe.h"
int main(){
Tribe t1;
Tribe t2;
char nameTribe1[20];
int maxTribe1;
cout << "Enter name of first tribe: " << endl;
cin >> nameTribe1;
cout << "Enter max of survivors to first tribe(max 100): " << endl;
cin >> maxTribe1;
t1.tribe(nameTribe1, maxTribe1);
char nameTribe2[20];
int maxTribe2;
cout << "Enter name of second tribe: " << endl;
cin >> nameTribe2;
cout << "Enter max of survivors to second tribe(max 100): " << endl;
cin >> maxTribe2;
t2.tribe(nameTribe2, maxTribe2);
return 0;
}
survivor headr:
class Survivor{
public:
char NameOfSurvivor[20];
int Age;
double StartWidgth;
double FinalWidgth;
void survivor(char name[20], int age, double sWidgth);
};
#endif
survivor cpp:
#include "survivor.h"
#include <iostream>
using namespace std;
void Survivor::survivor(char name[20], int age, double sWidgth){
for (int i = 0; i < 20; i++)
NameOfSurvivor[i] = name[i];
Age = age;
StartWidgth = sWidgth;
FinalWidgth = -1;
}//end survivor
tribe header:
class Tribe{
public:
char NameOfTribe[20];
int MaxSurvivorsInTribe;
**Survivor* SurvivorsArray = new Survivor[MaxSurvivorsInTribe];**
int NumbersOfSurvivorsInTribe;
void tribe(char name[20], int maxSurvivor);
};
#endif
tribe cpp:
#include "tribe.h"
#include <string>
#include <iostream>
using namespace std;
void Tribe::tribe(char name[20], int maxSurvivor){
for (int i = 0; i < 20; i++)
NameOfTribe[i] = name[i];
for (int i = 0; i < maxSurvivor; i++){
for (int j = 0; j < 20; j++){
SurvivorsArray[i].NameOfSurvivor[j] = ' ';
}//end for
SurvivorsArray[i].Age = 0;
SurvivorsArray[i].StartWidgth = 0;
SurvivorsArray[i].FinalWidgth = 0;
MaxSurvivorsInTribe = maxSurvivor;
NumbersOfSurvivorsInTribe = 0;
}//end for
}//end tribe
thank's.