C++基础学习---写写代码1
恰当的使用引用
main.h
class Time {
public:
void set_time(Time& t, int hour, int minu, int sec);
void show_time(Time& t);
private:
int hour;
int minu;
int sec;
};
main.cpp
#include<stdio.h>
#include<string.h>
#include<iostream>
#include "main.h"
void Time::set_time(Time& t, int hour, int minu, int sec)
{
t.hour = hour;
t.minu = minu;
t.sec = sec;
}
void Time::show_time(Time& t)
{
std::cout << t.hour <<":"<<t.minu<<":"<<t.sec<<std::endl;
}
int main(void)
{
Time t;
t.set_time(t,11,50,30);
t.show_time(t);
return 0;
}