无法理解未排序列表和通用数据类型
Trouble understanding Unsorted Lists and generic data types?
因此,我们在今天的Comp Sci 2课上了解了未排序列表-老师提到,使用未排序列表,您可以创建模拟任何数据的通用数据类型-但对该数据的操作被定义为特定的。这本书给出的例子如下:
#include “ItemType.h”
class UnsortedType // declares a class data type
{
public :
// 8 public member functions
void UnsortedType ( );
bool IsFull ( ) const;
int GetLength ( ) const ; // returns length of list
ItemType GetItem ( ItemType item, bool& found);
void PutItem ( ItemType item );
void DeleteItem ( ItemType item );
void ResetList ( );
ItemType GetNextItem ();
private :
// 3 private data members
int length;
ItemType info[MAX_ITEMS];
int currentPos;
};
我的问题是:当我试图重新创建这样的东西时,我是否必须制作一些专门称为ItemType的类?还是ItemType是要存储在未排序列表中的任何对象的占位符?(例如,您是否可以将ItemType替换为:phonebookContacts,其中phonebookContact类是一个包含电话簿中人员的联系信息的对象?)
是的,您可以用phonebookContact替换ItemType。
只需将每个ItemType替换为phonebookContact,并#包含一个类似phonebookContact.h的标头,而不是ItemType.h。标头phonebookContact.h需要包含phonebook联系人类的定义,因为ItemType.h可能包含ItemType类的定义。
阅读c++模板。模板化的类。以下是一个示例http://www.cplusplus.com/doc/tutorial/templates/
相关文章:
- 防止主数据类型C++的隐式转换
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 使用简单类型列表实现的指数编译时间.为什么
- 在C++中打印指向不同基元数据类型的指针的内存地址
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何计算数据类型的范围,例如int
- C++中数据类型修饰符的顺序
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- C++多种数据类型的列表.遗产
- 在数据类型类的列表中查找 elem
- QML自定义列表数据类型
- C++ 从文本文件数据类型读取为结构,并将数据存储在列表的向量中
- 抽象数据类型命名约定:(动态)数组,向量,序列,列表,容器,缓冲区
- 从自定义数据类型列表中删除时出现 C2678 错误
- 用于查询自定义数据类型列表的SQLite虚拟表
- 无法理解未排序列表和通用数据类型
- C#数组列表的C++等价物,用于保存多个数据类型
- 对抽象数据类型的stl::列表排序
- STL列表-作为指针对象的数据类型
- 八度值列表数据类型