#include <bits/stdc++.h>
using namespace std;
struct test{
int num=4;
string name;
test(){
num=3;name="init";
}
// friend string operator* (test&a,test&b){
// // cout<<a.name+b.name<<endl;
// return a.name+b.name;
// }
string operator* (test&b){
return this->name+b.name;
}
};
int main(){
test t1,t2;
t1.name="t1",t2.name="t2";
cout<<t1.num<<endl;
string str=t1 * t2;
cout<< str<<endl;
return 0;
}
C++结构体运算符重载函数
最新推荐文章于 2026-07-29 12:20:01 发布

5172

被折叠的 条评论
为什么被折叠?



