什么是驱动程序功能?

时间:2014-01-12 00:46:30

标签: c++

我正在研究“Accelerated C ++”。我对问题5-3有疑问。它问道:

5-3. By using a typedef, we can write one version of the program that implements either a
vector-based solution or a list-based one. Write and test this version of the program.'

接下来的问题是:

5-4. Look again at the driver functions you wrote in the previous exercise. Note that 
it is possible to write a driver that differs only in the declaration of the type for the data structure
that holds the input file. If your vector and list test drivers differ in any other way, rewrite them
so that they differ only in this declaration.

驱动程序的功能究竟是什么?我已经通过创建if语句以及重载函数来解决5-3来处理不同的数据类型,如下所示:

cout << "Please enter 1 if you would like to use vectors, or 2 if you would like to use lists: "<< endl;
int choose;
cin >> choose;
//CHOOSING TO USE VECTORS
if (choose == 1){....vector<Student_info> allStudents;
                 vector<Student_info> fail;.......} 

//CHOOSING TO USE LISTS
else if (choose==2) {....list<Student_info> allStudents;
                    list<Student_info> fail;....}

//INVALID CHOICE
else {...invalid number, try again...}

除了重载函数之外,我没有创建任何额外的函数来处理不同的数据类型。这些驱动程序功能?如果没有,我一定是在做错了。有人能解开一些光吗?产品:&gt;

2 个答案:

答案 0 :(得分:3)

在两个if块中,与allStudentsfail相关的代码有多相似,无论它们是list还是vector?如果您已正确完成任务,则可能很少或没有区别。现在,如果您取出该代码并删除对listvector的引用,而不是在使用mytypetypedef vector<Student_info> mytype构建的typedef list<Student_info> mytype上运行,那么您将拥有他们称之为“司机功能”。这不是一个正式的名称,你将找到互联网参考。他们只是描述驱动 listvector操作的代码以获得答案。

答案 1 :(得分:2)

在这种特殊情况下,驱动程序代码更难以说明测试代码

换句话说,作者建议您查看用于验证您在5-3中编写的代码的测试(也称为驱动程序)代码。