本文介绍了救命!错误C2082:重新定义形式参数'mang'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 #include iostream 使用 namespace std; typedef char * ptr; void nhapchuoi(ptr& mang, int & n) { cout<< \ nNhap so ky tu:; cin>> n; ptr mang = new char [n]; // 行错误!!!!!!!!!!!! 的类=code-keyword>( int i = 0 ; i< n ;我++)> { cout<< \ nNhap ky tu thu< ;< i<< :; cin>> mang [i]; } } void xuatchuoi(ptr mang, int n) { cout<< \ nTa co:; for ( int i = 0 ; I< N;我++)> { cout<< << mang [i ]。 } cout<< endl; } void chen(ptr mang, int n, char kytu) { if (n == 0 ) { n ++; ptr mang2 = new char [n]; mang [ 0 ] = kytu; } else { n ++; ptr mang2 = new char [n]; for ( int i = 0 ; i< n- 1 ; i ++) mang2 [i] = mang [i]; mang2 [n- 1 ] = kytu; delete [] mang; mang = mang2; } } void xetnguyenam(ptr mang, int n,ptr& mang2, int & n2) { cout<< \ nCac nguyen am:; for ( int i = 0 ; I< N;我++)> { if (mang [i] == ' a' || mang [i] == ' e' || mang [i] == ' i' || mang [i] == ' o' || mang [i] == ' u') { cout<< << mang [i]; // chen(mang2,n2,mang [i]); } } } void main() { ptr mang1,mang2; int n1,n2; nhapchuoi(mang1,n1); xuatchuoi(mang1,n1); xetnguyenam(mang1,n1,mang2,n2); // cout<<\ nCac ky tu nguyen am:; // xuatchuoi(mang2,n2); system( pause); } 解决方案 mang 是你的参数之一函数,所以你有一个该名称的变量。你不能用这个名字声明第二个变量... 第一个声明: 无效 nhapchuoi(ptr& mang , int & n) 第二次声明: ptr mang = new char [n]; 如果你想为该变量赋值而不是从行的开头删除类型定义: ptr mang = new char [N]; #include"iostream"using namespace std;typedef char* ptr;void nhapchuoi(ptr &mang, int &n){cout<<"\nNhap so ky tu: ";cin>>n;ptr mang = new char[n]; //line error!!!!!!!!!!!!for(int i=0;i<n;i++)>{cout<<"\nNhap ky tu thu "<<i<<" : ";cin>>mang[i];}}void xuatchuoi(ptr mang, int n){cout<<"\nTa co: ";for(int i=0;i<n;i++)>{cout<<" "<<mang[i];}cout<<endl;}void chen(ptr mang, int n, char kytu){if(n==0){n++;ptr mang2 = new char [n];mang[0] = kytu;}else{n++;ptr mang2 = new char[n];for(int i=0;i< n-1;i++)mang2[i]=mang[i];mang2[n-1]=kytu;delete[]mang;mang=mang2;}}void xetnguyenam(ptr mang, int n, ptr &mang2, int &n2){cout<<"\nCac nguyen am: ";for(int i=0;i<n;i++)>{if(mang[i]=='a' || mang[i]=='e' || mang[i]=='i' || mang[i]=='o' || mang[i]=='u'){cout<<" "<<mang[i];//chen(mang2,n2,mang[i]);}} }void main(){ptr mang1, mang2;int n1,n2;nhapchuoi(mang1,n1);xuatchuoi(mang1,n1);xetnguyenam(mang1,n1,mang2,n2);//cout<<"\nCac ky tu nguyen am: ";//xuatchuoi(mang2,n2);system("pause");} 解决方案 mang is one of the parameters of your function, so you have a variable by that name. You can not declare a second variable with that name...First declaration:void nhapchuoi(ptr &mang, int &n)Second declaration:ptr mang = new char[n];If you mean to assign value to that variable than remove the type definition form the beginning of the line:ptr mang = new char[n]; 这篇关于救命!错误C2082:重新定义形式参数'mang'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 10:29