#include "子函数3.h"
#include <iostream>//尝试过把这两个库函数放在,自定义的函数中,但不行
using namespace std; //因为只有在调用自定义函数的情况下(就是使用swap),才去找这个文件,找到之后,
//使用完之后就退出,那么当使用“cout",就会发现没有定义,因为确实没有declared iostream 这个函数库
int main()//那么想说的就是:**先定义后使用**。
{
int m=11,n=29;
swap(m,n);
cout<<m<<' '<<n;
return 0;;
}
库函数如此,其他也一样。
#include <iostream>
using namespace std;
class time
{
public:
int hour;
int minute;
int second;
};
int show_time(time *t) //为什么会出错????
{//在使用time来定义t的时候,必须要在该文件下定义time;(这和所有的形式参数一样,先定义后使用)
int m;
for(m=0;m<2;m++)
{
cin>>t[m].hour>>t[m].minute >>t[m].second ;//在这里可以添加上hour minute second的范围
cout<<t[m].hour <<":"<<t[m].minute <<':'<<t[m].second <<endl;
}
return 0;
}
这是主函数
#include <iostream>
#include "例题2.3子函数.cpp"
using namespace std;
int main()
{
int n;
cin>>n;
time *t=new time;
show_time(t);
return 0;
}
time必须在定义之后才能使用,也就是将class time放在子函数的文件夹中。