用date类定制一个模板set
#define _CRT_SECURE_NO_WARNINGS
#include
using namespace std;
class date
{
int hour, minute, second;
public:
date(int m_hour, int m_minute, int m_second) :hour(m_hour), minute(m_minute), second(m_second) {};/*同上*/
friend ostream& operator <<(ostream& os, const date* a)
{
os << a->hour << "时" << a->minute << "分" << a->second << "秒" << endl;
return os;
}
};
template<class type>
class set
{
type t;
public:
set(type st) :t(st) {};
void dispaly()
{
cout << t << endl;
}
};
class set
{
date*t;
public:
set(date*st) :t(st) {};
void dispaly()
{
cout << "现在的时间是"<int main()
{
setd1 = date(17, 3, 36);
d1.dispaly();
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
class date {
int hour, minute, second;
public:
date(int m_hour, int m_minute, int m_second)
: hour(m_hour), minute(m_minute), second(m_second){}; /*同上*/
friend ostream &operator<<(ostream &os, const date *a) {
os << a->hour << "时" << a->minute << "分" << a->second << "秒" << endl;
return os;
}
};
template <class type> class set {
type t;
public:
set(type st) : t(st){};
void dispaly() { cout << t << endl; }
};
template <> class set<date> {
date *t;
public:
set(date *st) : t(st){};
void dispaly() { cout << "现在的时间是" << t << endl; }
};
int main() {
date d(17, 3, 36);
set<date> d1 = &d;
d1.dispaly();
return 0;
}