#include <iostream> using namespace std; class point { private: int h,m,s; public: void set_time(int a1,int a2,int a3); void show_time();//成员函数 }; void point::set_time(int a1,int a2,int a3) { h=a1; m=a2; s=a3; // cin>>h>>m>>s;//直接输入到内存里面去,是类的数据成员,无需从新定义,这是在成员函数里面输入时分秒,不是在主函数中 //而最经常使用的就是在函数中进行初始化输入 } void point::show_time() { cout<<h<<":"<<m<<":"<<s<<endl; } int main() { int a1,a2,a3; cin>>a1>>a2>>a3;//这是在主函数中输入数据成员用来初始化time函数 point t; t.set_time(a1,a2,a3);//使用对象调用函数 t.show_time(); return 0; }