根据头文件Studenthpp完善Student类maincpp#include iostream#include Studenthppusing namespace std;void displayStudentStudent &student1 Student &student2 cout student1 id student1getId endl; cout stud
Student.hpp
#ifndef STUDENT_HPP #define STUDENT_HPP
#include "Date.hpp"
class Student { public: Student(int id, int year, int month, int day); ~Student(); int getId(); Date* getBirthDate() const; static int getNumberOfObjects(); //return the number of Student objects
private: int id; Date* birthDate; static int numberOfObjects; //count the number of Student objects };
#endif
Student.cpp
#include "Student.hpp"
#include
int Student::numberOfObjects = 0;
Student::Student(int id, int year, int month, int day) { this->id = id; birthDate = new Date(year, month, day); numberOfObjects++; }
Student::~Student() { delete birthDate; numberOfObjects--; }
int Student::getId() { return id; }
Date* Student::getBirthDate() const { return birthDate; }
int Student::getNumberOfObjects() { return numberOfObjects;
原文地址: https://www.cveoy.top/t/topic/hFC9 著作权归作者所有。请勿转载和采集!