开辟空间
#include<iostream.h>#include<stdlib.h>
class time
{
private:
int hour;
int minute;
int sec;
public:
void input(time *p);
void output(time *p);
};
void time::input(time *p)
{
cout<<"please enter hour";
cin>>p->hour;
cout<<"please enter minute";
cin>>p->minute;
cout<<"please enter sec";
cin>>p->sec;
}
void time::output(time *p)
{
cout<<p->hour<<":"<<p->minute<<":"<<p->sec<<endl;
}
int main()
{
time *p;
p=(time*)malloc(sizeof(int));
input(p);
output(p);
free(p);
return 0;
}