Dynamic memory bug

I created the 2d array called activity in the following data structure. Although I have initialised it, it seems to be not initialised because I keep getting a seg fault at line 37. Someone please look it over because I have no idea what to do for it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
struct Dorm
{
   int foodNeed, numDays, *food_per_day, Pop, **activity;
public:
   Dorm (int n, int f)
   :foodNeed(f), numDays(n), food_per_day(new int[numDays]), Pop(0), 
   activity(new int *[n])
   {
      for (int c = 0; c < numDays; ++c)
      {
	 activity[c] = new int [numDays+1];//Initialised here no?
	 memset (activity, 0, sizeof activity[c]);
	 scanf("%d", &food_per_day[c]);
	 food_per_day[c] -= foodNeed;
      }
   }
   
   bool operator() (frend uno, frend duo)
   {
      return ((uno.food < duo.food)); 
   }
   vector <frend> Berland;
   
   void Print();
   
   void Get()
   {
      sort(Berland.begin(), Berland.end(), *this);//sort in order of lowest need for food to highest
      FI it;
      for (int p = 0, i; p < numDays; ++p)
      {
	 for (it = Berland.begin(), i = 1; it != Berland.end() && (food_per_day[p] - (*it).food >= 0); ++it)
	 {
	    if (isBetween((*it).start, p+1, (*it).end))
	    {
	       food_per_day[p] -= (*it).food, ++Pop;
	       ++activity[p][0];
	       activity[p][i++] = (*it).num;
	    }
	 }
	 p+1 < numDays ? food_per_day[p+1] += food_per_day[p] : 0;
      }
      Print();
   }
};
Last edited on
Whoops I spot the mistake...line 12
Topic archived. No new replies allowed.