摘要: 1. 模板的概念。我们已经学过重载(Overloading),对重载函数而言,C++的检查机制能通过函数参数的不同及所属类的不同。正确的调用重载函数。例如,为求两个数的最大值,我们定义MAX()函数需要对不同的数据类型分别定义不同重载(Overload)版本。//函数1.int max(int x,int y); {return(x>y)?x:y ;}//函数2. float max( float x,float y){ return (x>y)? x:y ;}//函数3. double max(double x,double y) {return (c>y)? x:y ;} 阅读全文
posted @ 2013-01-22 10:19 诸葛风雨 阅读(476) 评论(0) 推荐(0) 编辑
摘要: // similar to uncreate, but no need to return memorytemplate <class T> void Vec<T>::clear(){ if (data) { // destroy (in reverse order) the elements that were constructed iterator it = avail; while (it != data) Vec<T>::alloc.destroy(--it); } data = avail = limit = 0;}// using the ke 阅读全文
posted @ 2013-01-22 10:18 诸葛风雨 阅读(360) 评论(0) 推荐(0) 编辑