0

I am trying to look at specific items (strings) in the object array and parse the strings but the error at weekData.at(i) says "expression must have class type but it has type "WeekData *" ".

double Stats::GetMean(WeekData weekData[], int num){
    vector<string> dateV;
    vector<int> deathV;
    double mean = 0;
    int total = 0;

    for(int i = 0; i<num;i++){
        string line = weekData.at(i); **//ERROR**
        stringstream ss(line);
        while(ss.good()) {
            string week;
            string death;
            getline(ss, week, ',');
            getline(ss, death, ',');
            int deaths = atoi(death.c_str());
            dateV.push_back(week);
            deathV.push_back(deaths);
            total = total+deaths;
        }
    }
   return mean = total/num;
}

The error at weekData.at(i) says "expression must have class type but it has type "WeekData *" ".

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445

1 Answers1

0

You passed weekData in as an array type in WeekData weekData[]. Which is equivalent to passing in a pointer to the first element of an array like WeekData *.

So at this line

string line = weekData.at(i);

The compiler sees a pointer to a WeekData object, tries to use the . dot operator on it, and fails. The line you need is.

string line = weekData[i];
JimmyNJ
  • 1,134
  • 1
  • 8
  • 23