A question about const

Here is the codes. Basically I am not sure the difference between the 'const' in front of the function's name and the 'front' behind of the function's name.Well, I just tried this program, and got a segment error.

Thanks for helping
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
46
47
48
#include <string>
#include <iostream>
using namespace std;

class student{
 private:
 string firstName;
 string lastName;
 int age;
 int * scores; 

 public:
  void setFirstName(string firstName);
  string getFirstName() const;
  void setLastName(string lastName);
  string getLastName() const ;
  void printSchool(string school = "Computer Science ");

  void setScores(int * scores); 
  int * getScores() const; 
  int getAge() const;
  void setAge(int age);
  int getScore() const;
  void setScore(int score);
  
  student();
  student(string fn, string ln, int age, int * scores);
  student& operator= (const student & s);
};


int student::getScore() const{
  return *scores;
}

student::student(){
  firstName="0";
  lastName="0";
  age=0;
  *scores=0;
}
int main(){
  student a;
  cout<<a.getScore()<<endl;

  return 0;
}
I have done it by myself....

I need to allocate some space for the pointer first..
Topic archived. No new replies allowed.