这是我的实现
Film.h //标题
#ifndef FILM_H
#define FILM_H
#include <QString>
class Film {
protected:
QString title;
double dailyRate;
public:
Film(QString ti,double dr);
virtual double calculateRental(int num)const;
};
#endif // FILM_H
电影.cpp
#include "film.h"
#include <QString>
Film::Film(QString ti,double dr){
title=ti;
dailyRate=dr;
}
double Film::calculateRental(int num)const {
return dailyRate*num;
}
主文件
#include <QtCore/QCoreApplication>
#include <QtCore/QTextStream>
#include "film.h"
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
QTextStream cout(stdout, QIODevice::WriteOnly);
Film f("Top Gun", 10.00); //create an instance of a film
cout <<f.calculateRental(2);
return a.exec();
}
如何计算创建的 Film 实例的数量?我知道是这样的:
static int numOfFilms;
numOfFilms++;
我如何使用代码?