我正在编写一个应该接收书籍对象列表作为参数的函数。在每个书籍对象中都有一个私有数据成员价格。该功能假设比较每本书的价格并返回价格最高的书。
//Client program
#include <iostream>
#include "Book.h"
#include "textbook.h"
#include "Name.h"
#include "unsorted.h"
using namespace std;
int main()
{
book b1("The Exception to the Rulers", "Amy", "Goodman", "Hyperion", 342, "1-4013-0131", 21.95,'N'); // this is the title, authors first & last name, publisher, number of pages, isbn number, price, and code.
book b2("Who moved my cheese", "Spencer", "Johnson", "Red Tree", 95, "0-399-14446-3", 19.99, 'H');
book b3("Hellbound Hearts", "Neil", "Gaiman", "Dark Harvest", 326, "978-1-4391-4090-1", 16.00, 'F');
UnsortedType L1; // creating a list "L1" with the default vaule lengh 0
L1.InsertItem(b1); // populating the list with the first book
L1.InsertItem(b2); // populating the list with the second book
L1.InsertItem(b3); // populating the list with the third book
主要是我不确定如何将实际列表“L1”或 L1 的内容传递给将比较价格的函数。我想我很困惑,因为为了调用函数 getMostExpensive 我会做一些类似的事情:
L1.getMostExpensive();
但是如果我用 L1 调用我的函数,我是否必须传递任何参数,如果没有,那么我如何访问函数 getMostExpensive() 内部的私有数据成员价格?