[英]what exactly are driver functions?
I'm working through "Accelerated C++". 我正在通过“加速的C ++”进行工作。 I have a question about problem 5-3. 我对问题5-3有疑问。 It asks: 它要求:
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.'
The next question asks: 下一个问题问:
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.
What exactly are driver functions? 驱动程序功能到底是什么? I've solved 5-3 by creating if statements as well as overloaded functions to deal with different datatypes like so: 通过创建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...}
I did not create any extra functions besides the overloaded ones to deal with different data types. 除了重载的函数以外,我没有创建任何其他函数来处理不同的数据类型。 Are those driver functions? 这些驱动程序功能吗? If not, I must be doing the problem wrong. 如果没有,那我一定做错了问题。 Could someone shed some light? 有人可以照亮吗? :> :>
Inside your two if
blocks, how similar is the code that operates on allStudents
and fail
regardless of whether they are list
or vector
? 在您的两个if
块中,对allStudents
且无论它们是list
还是vector
都fail
的代码有多相似? If you've done the assignment correctly, there is probably little or no difference. 如果您已正确完成分配,则可能几乎没有差异。 Now if you take that code out and remove references to list
and vector
and instead operate on mytype
where you build either with typedef vector<Student_info> mytype
or typedef list<Student_info> mytype
you will have what they were calling a "driver function". 现在,如果你把这些代码并删除对list
和vector
,而是在操作mytype
,你与建或者typedef vector<Student_info> mytype
或typedef list<Student_info> mytype
你将有什么他们调用“驱动程序功能”。 It's not a formal name you're going to find internet references to. 您不会在互联网上找到它的正式名称。 They were just describing the code that drives the list
and vector
operations to get the answer. 他们只是在描述驱动 list
和vector
操作以获取答案的代码。
In this particular case, driver code is a more obscure way to say test code . 在这种特殊情况下,驱动程序代码是说测试代码的一种比较晦涩的方式。
In other words the author is suggesting you take a look at the test (aka driver) code you used to verify the code you wrote in 5-3. 换句话说,作者建议您看一下用来验证在5-3中编写的代码的测试(aka驱动程序)代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.