這是我的代碼:串C++操作符重載 - 我真的不明白這一點
#include <iostream>
#include <string.h>
using namespace std;
string& operator+(string & lhs, int & rhs) {
char temp[255];
itoa(rhs,temp,10);
return lhs += temp;
}
int main() {
string text = "test ";
string result = text + 10;
}
結果是:
test.cpp: In function 'int main()':
test.cpp:15:26: error: no match for 'operator+' in 'text + 10'
test.cpp:15:26: note: candidates are:
/.../
而且應該是test 10
。