0

I am Attempting to Initialize an array of structures, the user will be prompted to enter information, and I will then store it and display it though my structure array. I am having difficulties however initializing the contents of my array to 0.

const int SIZE = 10;

struct Rabbit {
string Fname;
string Lname;
int Fltnum;
int Priority;
};

class Deer {

Rabbit Value[SIZE];
public:

int Initialize();
char Input();
char Display();
};




int Deer::Initialize()
{   

for (int i = 0; i < 10; i++) {
    Rabbit Value[i] = 0;
}

The error is with my Rabbit Value [i], it saying

"int i Error: Expression must have a constant value".

Marat
  • 15,215
  • 2
  • 39
  • 48
eggo
  • 83
  • 1
  • 6
  • So what does `Rabbit Value[i] = 0;` statement mean? – zerkms Feb 18 '17 at 04:58
  • I'm trying to make all of the indexes = 0, That way when inputting/displaying data using that Array I can stop when I hit a null value, So for instance Say the User inputs data 3 different times, I want to display data only 3 times, not the full 10 which is the size of the array – eggo Feb 18 '17 at 05:02
  • So where is the object that holds an array of `Value`s? – zerkms Feb 18 '17 at 05:05
  • I suppose there is none. Are you saying I need to create a constructor of my structure type to use my Array? Later in my code, I have an obj of my Class type to access my functions from main. Is this not enough to use my Array? – eggo Feb 18 '17 at 05:18
  • 2
    In C++ you use constructors for that kind of thing. `Deer() : Value() {}`. – juanchopanza Feb 18 '17 at 05:45
  • what would it mean to make a Rabbit `0` ? A rabbit has 2 strings and 2 ints. – M.M Feb 18 '17 at 07:09
  • `Rabbit Value[i] = 0;` looks like you are defining a new local variable, instead of assigning to the `Deer` member variable -- the compiler thinks that `i` is the number of elements in this new array. What you want is just `Value[i] = 0;`, but this still has the problem that `0` is not appropriate for assigning to a strcut with mixed strings and ints. – Christopher Oicles Feb 18 '17 at 09:36

0 Answers0