c++ - 构造函数错误 : Expected an identifier?

标签 c++ oop

我正在处理一堆具有组合的类,当我尝试实现构造函数时,我不断收到此错误(预期的标识符),这里是类头:

#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/

相关文章:

c++ - 隐式默认可构造的含义?

java - 如何以OO方式修改返回值设计?

面向对象。选择对象

c++ - 快速整数矩阵乘法与 bit-twiddling hacks

c++ - Ubuntu 12.10 - 编译 C++ 程序时找不到 -ltcl

C++ 组合模板扩展

c++ - 为什么没有抓到返回值就没有错误呢?

c++ - dynamic_cast的继承与使用

javascript - Javascript 构造函数中函数声明的差异

python - 如何在 sympy 中向扩展 `Poly` 类的类添加参数?