摘要:
//《C++编程——数据结构与程序设计方法》15.8.3#include#include #include "arrayListType.h"using namespace std;templatearrayListType::arrayListType(int size)//(int size=100)是错的??{if(sizearrayListType::~arrayListType(){delete [] list;}templatevoid arrayListType::print() const{int i;for(i=0;ivoid arrayListType: 阅读全文
摘要:
//《C++编程——数据结构与程序设计方法》例15.8//利用函数重载技术,求两个整数、字符、浮点数或字符串中的较大值,需要编写4个函数larger。//而C++通过提供函数模板,简化了重载函数据的过程。#include using namespace std;template//Type,模板的形参,用于确定函数的形参,返回值类型,还用于在函数中声明变量。Type larger(Type x,Type y);int main(){coutType larger(Type x,Type y){if(x>=y)return x;elsereturn y;} 阅读全文