![]() |
#2
peach54602013-04-18 21:05
|
题目:在Student_info 类中加入计数代码,计算一下对象被创建,复制,赋值或者删除的次数.用这个可计数的类运行第六章的学生成绩程序.使用这个其有计数功能的Student_info类可以算出在库中的算法进行了多少次复制操作.对比库中不同的类测到的复制次数,可以估计出这些不同的类对资源的消耗量.试一试进行计数并对结果进行分析.
Student_info类:

class Student_info
{
public:
Student_info(); //构造一个空的 Student_info 对象
Student_info(std::istream&); //读一个流从而构造一个对象
std::string name() const { return n; }
bool valid() const { return !homework.empty(); }
std::istream& read(std::istream&);
double grade() const;
private:
std::string n;
double midterm, final;
std::vector<double> homework;
};
bool compare(const Student_info&, const Student_info&);
{
public:
Student_info(); //构造一个空的 Student_info 对象
Student_info(std::istream&); //读一个流从而构造一个对象
std::string name() const { return n; }
bool valid() const { return !homework.empty(); }
std::istream& read(std::istream&);
double grade() const;
private:
std::string n;
double midterm, final;
std::vector<double> homework;
};
bool compare(const Student_info&, const Student_info&);
我只想到了在每次调用创建,复制,赋值等操作的时候手动调用一次计数函数.
怎样自动判断调用了复制构造函数,自动计数呢?
[ 本帖最后由 jxlcs 于 2013-4-18 21:48 编辑 ]