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;
}
posted @ 2021-03-06 00:04  WangCoder  阅读(65)  评论(0编辑  收藏  举报