Ken H

Ken H

  • NA
  • 646
  • 354.8k

An error occurred while initializing data members.

Dec 8 2013 1:02 AM
Hello friend,
  
      I tried on a class member data error occurred while initializing.

System prompts an error message:error C2059: syntax error : '{'
                                                        error C2143: syntax error : missing ';' before '{'
                                                        error C2143: syntax error : missing ';' before '}'

My codes is as follows:

#include<iostream>
using namespace std;
#define COURSE_NUM 4

class Student  
{
   public:
Student();
        void ResetScore(int index,int new_score);
    private:
float score[COURSE_NUM];
};

Student::Student(){
this->score[COURSE_NUM]={0.0}; // Attempting to initialize the array.
}

void Student::ResetScore(int index,int new_score)
{
this->score[index]=new_score;
}

int main()
{
        Student stu;
stu.ResetScore(1,98.5);

return 1;
}


Thanks.

Answers (4)