Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error at constructor : Expected an identifier?

Tags:

c++

oop

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 &){}
like image 713
Abd Al Rahman Hamdan Avatar asked Mar 23 '26 03:03

Abd Al Rahman Hamdan


1 Answers

Your constructor should be defined the following way

Student::Student() { /* some code */ } 
like image 153
Vlad from Moscow Avatar answered Mar 24 '26 17:03

Vlad from Moscow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!