文件名称:DArray-Template-better
-
所属分类:
- 标签属性:
- 上传时间:2012-11-16
-
文件大小:271.61kb
-
已下载:1次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
现在实现的类已经比较好了,用户使用起来很方便。
但是,新的问题又出来了。
上述的动态数组只能存储double类型的数据。想象一下,另一个用户也想用这个动态数组,但是他处理的数据是int类型的,该如何办?
当然,你可以再写一个基于int类型的动态数组类,你发现,大部分的代码都不要改动,只要将类型double变成int即可。
如果另一个用户需要处理的是float类型,还有用户处理的是char类型的….该怎么办?
这样做的缺点很显然:
这些类的代码大同小异,代码冗余;
当对这个类进行修改时,所有的这些类都要同时改,不利于代码维护;
有无办法解决这个问题?即,如果能把变量的“类型”也当作一个“变量”,不就可以了吗?这个在C中是不能解决的,但是在C++中,有一种新的机制template,就可以解决上述问题。Template的使用非常简单,大致的形式见:
-Now the class has been better achieved, and the user is easy to use.
However, the new issue came out again.
The dynamic array can store double types of data. Imagine, another user would like to use this dynamic array, but his handling of the data is int type, how do?
Of course, you can write a dynamic array of type int-based class, you find that most of the code have not changed, simply type int can become double.
If another user needs to be addressed is the float type, there is the user dealing with the char type .... How to do?
This disadvantage is clear:
similar code for these classes, code redundancy
When the right to modify this class, all of these classes should also change, is not conducive to code maintenance
Any other way to solve this problem? That is, if the variable can "type" also as a "variable", not to the information? This can not be solved in C, but in C++, there is a new mechanism template, you can solve these problems.
但是,新的问题又出来了。
上述的动态数组只能存储double类型的数据。想象一下,另一个用户也想用这个动态数组,但是他处理的数据是int类型的,该如何办?
当然,你可以再写一个基于int类型的动态数组类,你发现,大部分的代码都不要改动,只要将类型double变成int即可。
如果另一个用户需要处理的是float类型,还有用户处理的是char类型的….该怎么办?
这样做的缺点很显然:
这些类的代码大同小异,代码冗余;
当对这个类进行修改时,所有的这些类都要同时改,不利于代码维护;
有无办法解决这个问题?即,如果能把变量的“类型”也当作一个“变量”,不就可以了吗?这个在C中是不能解决的,但是在C++中,有一种新的机制template,就可以解决上述问题。Template的使用非常简单,大致的形式见:
-Now the class has been better achieved, and the user is easy to use.
However, the new issue came out again.
The dynamic array can store double types of data. Imagine, another user would like to use this dynamic array, but his handling of the data is int type, how do?
Of course, you can write a dynamic array of type int-based class, you find that most of the code have not changed, simply type int can become double.
If another user needs to be addressed is the float type, there is the user dealing with the char type .... How to do?
This disadvantage is clear:
similar code for these classes, code redundancy
When the right to modify this class, all of these classes should also change, is not conducive to code maintenance
Any other way to solve this problem? That is, if the variable can "type" also as a "variable", not to the information? This can not be solved in C, but in C++, there is a new mechanism template, you can solve these problems.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
DArray-Template-better/DynamicArray.dsw
DArray-Template-better/DynamicArray.ncb
DArray-Template-better/DynamicArray.plg
DArray-Template-better/DynamicArray.dsp
DArray-Template-better/Debug/vc60.idb
DArray-Template-better/Debug/vc60.pdb
DArray-Template-better/Debug/DynamicArray.exe
DArray-Template-better/Debug/DynamicArray.pdb
DArray-Template-better/Debug/main.obj
DArray-Template-better/Debug/DynamicArray.pch
DArray-Template-better/Debug/DArray.obj
DArray-Template-better/Debug/DynamicArray.ilk
DArray-Template-better/DArray.cpp
DArray-Template-better/main.cpp
DArray-Template-better/DArray.h
DArray-Template-better/DynamicArray.opt
DArray-Template-better/Debug
DArray-Template-better
DArray-Template-better/DynamicArray.ncb
DArray-Template-better/DynamicArray.plg
DArray-Template-better/DynamicArray.dsp
DArray-Template-better/Debug/vc60.idb
DArray-Template-better/Debug/vc60.pdb
DArray-Template-better/Debug/DynamicArray.exe
DArray-Template-better/Debug/DynamicArray.pdb
DArray-Template-better/Debug/main.obj
DArray-Template-better/Debug/DynamicArray.pch
DArray-Template-better/Debug/DArray.obj
DArray-Template-better/Debug/DynamicArray.ilk
DArray-Template-better/DArray.cpp
DArray-Template-better/main.cpp
DArray-Template-better/DArray.h
DArray-Template-better/DynamicArray.opt
DArray-Template-better/Debug
DArray-Template-better
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.