我正在处理一堆具有组合的类,当我尝试实现构造函数时,我不断收到此错误(预期的标识符),这里是类头:
#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
我需要做什么来解决这个错误?
这是 cpp,但我仍然没有实现其他 io 函数,因为我想先解决那个错误..
#include "Student.h"
Student::Student(){}
ostream & operator<<(ostream &, Student &){}
istream & operator>>(istream &, Student &){}
最佳答案
您的构造函数应按以下方式定义
Student::Student() { /* some code */ }
关于c++ - 构造函数错误 : Expected an identifier?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764280/