Reputation: 31
I am working with a bunch of classes with composition and I keep getting this error (Expected an identifier) when I try to implement the constructor , here the class header:
#ifndef STUDENT_H_
#define STUDENT_H_
#include "University.h"
class Student {
public:
Student(); // constructor
friend ostream & operator<<(ostream &, Student &); // print the student data
friend istream & operator>>(istream &, Student &); // to read student data
private:
const int id;
string name;
int marks[5];
Date admissionDate; // Composition
University university; // Composition
};
#endif
what do I need to do to solve this error ?
here's the cpp but I still did not implement the other io functions because I want to solve that error first..
#include "Student.h"
Student::Student(){}
ostream & operator<<(ostream &, Student &){}
istream & operator>>(istream &, Student &){}
Upvotes: 3
Views: 46559
Reputation: 2137
Since a Student
has a const int id
member, you need to initialize it in the constructor's
initialization list. E.g.:
Student::Student() : id(0)
{ }
Upvotes: 2
Reputation: 310960
Your constructor should be defined the following way
Student::Student() { /* some code */ }
Upvotes: 3