VC 中关于类的问题

来源:百度知道 编辑:UC知道 时间:2024/06/02 17:15:59
#include<iostream.h>
class Time
{
private:
int hour;
int minute;
int second;
public:
Time (int,int,int);
~Time ();

};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
cout<<"the time is: "<<h<<":"<<m<<":"<<s<<":"<<endl;
}
Time::~Time()
{
cout<<"the time is: "<<h<<":"<<m<<":"<<s<<":"<<endl;
}

void main(void)
{
Time t1(12,32,28);
Time t2(11,12,13);
}

就是这个程序 ,哪里有错?
调试的时候显示的是
error C2065: 'h' : undeclared identifier
error C2065: 'm' : undeclared identifier
error C2065: 's' : undeclared identifier

就是说在析构函数中没有定义h,m,s。但是析构函数不是不能带有参数的吗?不理解啊。。。学类感觉蛮难的。。。

析构函数中的h,m,s未定义,在析构函数应该这样写:
cout<<"the time is: "<<hour<<":"<<minute<<":"<<secound<<":"<<endl;因为你在构造函数中已经对这三个成员赋值了,所以会得到正确的值.

undeclared identifier
未定义的标识符(参数)……谢谢
Time (int,int,int);
改成
Time (int h,int m,int s);