什么是驱动程序功能?

zzz*_*991 5 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.'
Run Code Online (Sandbox Code Playgroud)

接下来的问题是:

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.
Run Code Online (Sandbox Code Playgroud)

什么是驱动程序功能?我通过创建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...}
Run Code Online (Sandbox Code Playgroud)

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

Ben*_*son 3

在你的两个块中,无论它们是or if,运行的代码有多相似?如果您正确完成了作业,则可能差别很小或没有差别。现在,如果您取出该代码并删除对和 的引用,而是在您构建的位置进行操作,或者您将拥有他们所说的“驱动程序函数”。这不是您在互联网上可以找到的正式名称。他们只是描述驱动和操作以获得答案的代码。allStudentsfaillistvectorlistvectormytypetypedef vector<Student_info> mytypetypedef list<Student_info> mytypelistvector

  • @DavidJhoo我认为这个问题的具体目标是让你把它分成一个*函数*(这可能需要使用`typedef`单独编译以获得不同的类型)因为我打赌他们要做的下一件事是介绍*模板*并向您展示如何现在拥有“多类型驱动程序功能”(使用问题的尴尬语言) (2认同)