引用变量的函数调用问题
#include<iostream>#include<string>
using namespace std;
string version1(const string &s1, const string &s2);
const string &version2(string &s1, const string &s2);
const string &version3(string &s1, const string &s2);
int main()
{
string input;
string copy;
string result;
cout << "输入字符串: ";
getline(cin, input);
copy = input;
cout << "输入的字符串: " << input << endl;
result = version1(input, "***");
cout << "你的弦增强了: " << result << endl;
cout << "你原来的弦: " << input << endl;
result = version2(input, "###");
cout << "你的弦增强了: " << result << endl;
cout << "你原来的弦: " << input << endl;
cout << "重置原始字符串.\n";
input = copy;
version3(input, "@@@");
cout << "你的弦增强了: " << result << endl;
cout << "你原来的弦: " << input << endl;
system("pause");
return 0;
}
string version1(const string &s1, const string s2)
{
string temp;
temp = s2 + s1 + s2;
return temp;
}
const string &version2(string &s1, const string &s2)
{
s1 = s2 + s1 + s2;
return s1;
}
const string &version3(string &s1, const string &s2)
{
string temp;
temp = s2 + s1 + s2;
return s1;
}
错误提示:
3 IntelliSense: 有多个 重载函数 "version1" 实例与参数列表匹配:
函数 "version1(const std::string &s1, const std::string &s2)"
函数 "version1(const std::string &s1, std::string s2)"
参数类型为: (std::string, const char [4]) f:\2013_C++\测试\测试\程序清单8.7.cpp 18 11 测试