大学时代旧作。
模板类的继承是C++中较为高级的一种用法,其语法与普通C++类的继承略有差别。本文实例演示了一个通过C++模板类继承实现排序算法的案例。代码如下:
1. 实现List基类
#ifndef LIST_H
#define LIST_H
#include <iostream>
using std::cout;
using std::endl;
enum Error_code { underflow, overflow, range_error, success, not_present,fail};
const int max_list = 100;
template <class List_entry>
class List
{
// methods of List ADT
public:
List();
int size() const;
bool full() const;
bool empty() const;
void clear();

这篇博客介绍了C++中模板类的继承,通过一个实际的排序算法案例,展示了如何利用模板类继承来实现代码复用。文章包含List基类的实现以及测试代码。

1203

被折叠的 条评论
为什么被折叠?



