这是我的实施
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
Film.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;
}
的main.cpp
#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++;
我该如何使用代码?
答案 0 :(得分:3)
这取决于。如果您将Class
替换为class
,并且QString
具有来自const char*
的转换构造函数,则为是。