这是我的代码:
#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
。