标签:重载 注意 struct 一个 size pac 排列 type rtt
#include<iostream> #include<string> using namespace std; struct time{ time(int a,int b,int c):hour(a),minute(b),second(c){name = "";} int hour,minute,second; string name; // 成员函数 time operator + (const time &b){ return time(hour+b.hour,minute+b.minute,second+b.second); } //友元函数 friend time operator + (time a, time b){ time c(a.hour+b.hour,a.minute+b.minute,a.second+b.second); return c; } bool operator < (const time c)const{ return c.hour+c.minute > hour + minute; } //常用于STL容器的排序 friend ostream &operator << (ostream &out,time a){ out << a.hour << ":" << a.minute << ":" << a.second; } //重载输出 time &operator =(time &d){ hour = 2*d.hour; return *this; } //重载 = //重载() void operator()(string s){ s += name; cout << s; } }; int main(){ time t1(1,2,3); time t2(4,5,6); time t3 = t1 + t2; t3 = t3; t3.name = "Tom"; cout << t3 << endl; t3("Bob"); return 0; }
#include<iostream> #include<string> using namespace std; void f(int a){ cout << a; } void f(string a){ cout << a; } int main(){ f(123); f("123"); return 0; }
标签:重载 注意 struct 一个 size pac 排列 type rtt
原文地址:https://www.cnblogs.com/Cmathe/p/12263264.html