动态类型
動(dòng)態(tài)數(shù)據(jù)類型DymType相當(dāng)于一個(gè)多種不同數(shù)據(jù)類型組合在一起的"聚合類型",利用它作為橋梁可以轉(zhuǎn)換為其他各種各樣的數(shù)據(jù)類型。設(shè)計(jì)這種類型的目的在于可以方便的設(shè)計(jì)xml文件中所用的各種類型,即統(tǒng)一使用為DymType類型。
DymType類設(shè)計(jì)如下:
class?DymType
{
public:
? ??DymType(const DymType& dym);
? ??DymType(string&?dym);
? ??DymType(int dym);
? ??DymType(unsigned int?dym);
? ??DymType(double?dym);
?
? ? bool operator == (const string& dym);
? ??bool operator == (const int?dym);
? ? bool operator == (const double?dym);
?
? ? const?DymType & operator = (const string &dym);
? ??const?DymType & operator = (int dym);
? ??const?DymType & operator = (double dym);
?
? ??operator const string &();
? ??operator const int();
? ??operator const double();
? ??
? ? time_t time(); //還可以轉(zhuǎn)換為以秒為單位的時(shí)間
? ? void init() {
? ? ? ? dym_string = "";
? ? ? ? dym_int = 0;
? ? ? ? dym_time = 0;
? ? ? ? dym_double = 0;
? ? }
?
private:
? ? string? dym_string;
? ? int? dym_int;
? ? time_t? dym_time;
? ? double? dym_double;?
};
總結(jié)
- 上一篇: Android编程权威指南第3版 9.5
- 下一篇: 深圳驾考东森路考纪实(2012-8-4通