调试修改后的代码:
#include < iostream >
using namespace std;
class Time
{
public:
void set_time( void ); //公用成员函数
void show_time( void ); //公用成员函数
int hour;
int minute;
int sec;
};
Time t; //定义对象 t
void Time :: set_time( ) //在类外定义set_time函数
{
cin >> t.hour;
cin >> t.minute;
cin >> t.sec;
}
void Time :: show_time() //在类外定义show_time函数
{
cout << t.hour << " : " << t.minute << " : " << t.sec << endl;
}
int main()
{
t.set_time(); //调用对象t的成员函数set_time,向t的数据成员输入数据
t.show_time(); //调用对象t的成员函数show_time,向t的数据成员输入数据
return 0;
}