c ++更改函数的变量参数 [英] c++ change function's variable argument
本文介绍了c ++更改函数的变量参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变作为参数传递给这个函数的变量:
i want to change my variable passed as argument to this function:
bool verifyStudent(string id, string name, int grade, int points, string type) {
if(!verifyId(id)){
cerr << "Please enter 8 charactes id! format: YYMMDDCC\n";
cin >> id;
return false;
} else
if(!verifyName(name)){
cerr << "Please enter name to 35 characters!\n";
cin >> name;
return false;
} else
if(!verifyGrade(grade)){
cerr << "Please enter class between 8 and 12!\n";
cin >> grade;
return false;
} else
if(!verifyPoints(points)){
cerr << "Please enter points between 0 and 300!\n";
cin >> points;
return false;
} else
if(!verifyType(type)){
cerr << "Please enter 1 charater type! format: R,r - regional, D,d - district, N,n - national, I,i - international\n";
cin >> type;
return false;
} else {
return true;
}
}
我应该如何访问给定的变量并在其他函数未验证时更改它?
how i should get access to the given variable and change it when it isn't verified by other function?
这是我调用函数的方式:
here is the way i call the function:
verifyStudent(iId, iName, iGrade, iPoints, iType);
推荐答案
为了改变参数,你必须采用references:
In order to change the arguments, you would have to take references:
bool verifyStudent(string& id, string& name, int& grade, int& points, string& type)
虽然我想说这个函数不像 verifyAndCorrectStudentIfNeeded 那样verifyStudent.
Although I'd say that function is not verifyStudent as much as verifyAndCorrectStudentIfNeeded.
这篇关于c ++更改函数的变量参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文