time.h
#include<iostream> using namespace std; class Time { private: int hour; int minute; int second; public: void showtime(); Time(int h = 0, int m = 0, int s = 0); Time(Time& t) { hour = t.hour; minute = t.minute; second = t.second; } };
time.cpp
#include"time.h" void Time::showtime() { cout << hour << " " << minute << " " << second << endl; } Time::Time(int h,int m,int s) { hour = h; minute = m; second = s; }
源.cpp
#include"time.h" Time& fuzhi(Time& timee) { return timee; } Time* fuzhi(Time* timee) { return timee; } int main() { Time time1; time1.showtime(); Time* time2 = new Time(1, 1, 1); time2->showtime(); Time time2_ = fuzhi(*time2); time2_.showtime(); delete time2; Time& time3 = *new Time(time1); time3.showtime(); Time time3_ = *fuzhi(&time3); time3_.showtime(); delete& time3; }
标签:fuzhi,对象,time2,time3,int,showtime,Time From: https://www.cnblogs.com/ruoye123456/p/16967842.html