首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >驱动函数到底是什么?

驱动函数到底是什么?
EN

Stack Overflow用户
提问于 2014-01-12 00:46:30
回答 2查看 10.4K关注 0票数 5

我正在学习“加速C++”。我有个关于问题5-3的问题。它要求:

代码语言:javascript
运行
复制
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.'

下一个问题是:

代码语言:javascript
运行
复制
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问题,如下所示:

代码语言:javascript
运行
复制
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...}

除了重载的函数之外,我没有创建任何额外的函数来处理不同的数据类型。这些是司机的功能吗?如果没有,我一定是做错了问题。有人能开点光吗?:>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-12 00:58:11

在两个if块中,在allStudentsfail上操作的代码有多相似,而不管它们是list还是vector?如果你完成了正确的作业,可能没有什么区别。现在,如果您删除该代码,删除对listvector的引用,而在mytype上操作,使用typedef vector<Student_info> mytypetypedef list<Student_info> mytype构建,您将得到他们所称的“驱动函数”。这不是一个正式的名字,你会找到互联网的参考。他们只是描述驱动listvector操作以获得答案的代码。

票数 3
EN

Stack Overflow用户

发布于 2014-01-12 00:57:51

在这种特殊情况下,驱动程序代码是一种比较模糊的方法,可以说是测试代码

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21069897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档