引用问题,求大神解答
//想通过调用resetString(string& )和resetStringArray(string& arr[][2])函数改变主函数中已经定义好的字符串和字符串数组,可结果是只有字符串能顺利改变。数组部分编译失败。求大神教导#include<iostream>
#include<string>
using namespace std;
void resetString(string& );
void resetStringArray(string& arr[][2]);
int main()
{
/*----------------------------------*/
string ss="WENG";
cout<<"before:\n"<<ss<<endl;
resetString(ss);
cout<<"after:\n"<<ss<<endl;//可顺利运行;
/*--------------------------------*/
string arr[2][2]={{"a","b"},{"c","d"}};
cout<<"before:\n"<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++){cout<<"\t"<<arr[i][j];}
cout<<endl;
}
resetStringArray(arr[2][2]);
cout<<"after:\n"<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++){cout<<"\t"<<arr[i][j];}
cout<<endl;
}
system("pause");
return 0;
}
void resetString(string& a){a="HUANG";}
void resetStringArray(string& arr[][2]){arr[][2]={{"d","c"},{"b","a"}};}
[ 本帖最后由 wengbin 于 2015-9-24 11:16 编辑 ]