关于一个类模板的程序,请高手帮帮忙哈

point_net 2008-03-26 05:08:59
#include<iostream>
using namespace std;
template<class type>
class Time
{
public:
Time(type a,type b,type c,type d,type e,type f)
{
hour=a;
minute=b;
sec=c;
month=d;
day=e;
year=f;
}
void display();
private:
type hour;
type minute;
type sec;
type month;
type day;
type year;
};
/*Time::Time<type>(type a,type b,type c,type d,type e,type f)
{
hour=a;
minute=b;
sec=c;
month=d;
day=e;
year=f;
}*/
void Time<type> ::display()
{
cout<<month<<"/"<<day<<"/"<<year<<endl;
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
int main()
{
Time<int> t1(10,13,56,12,25,2004);
t1.display();
return 0;
}
编译有不少错误,是不是类模板错了,还是类模板外定义函数错了?还是都错了,请高手指点一下哈
...全文
25 1 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ryfdizuo 2008-03-26
  • 打赏
  • 举报
回复
template<class type> //加上
void Time<type>::display()
{
cout <<month <<"/" <<day <<"/" <<year <<endl;
cout <<hour <<":" <<minute <<":" <<sec <<endl;
}
相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-03-26 05:08
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下