c++ change function's variable argument

后端 未结 2 1955
小鲜肉
小鲜肉 2020-12-07 03:59

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(!verify         


        
相关标签:
2条回答
  • 2020-12-07 04:00

    Quote:

    Therefore, C++ has two parameter passing mechanisms, call by value (as in Java) and call by reference. When a parameter is passed by reference, the function can modify the original. Call by reference is indcated by an & behind the parameter type.

    Here is a typical function that takes advantage of call by reference [...]

    void swap(int& a, int& b) { [...] }

    More here -> A3.5. Functions

    0 讨论(0)
  • 2020-12-07 04:09

    In order to change the arguments, you would have to take references:

    bool verifyStudent(string& id, string& name, int& grade, int& points, string& type) 
    

    Although I'd say that function is not verifyStudent as much as verifyAndCorrectStudentIfNeeded.

    0 讨论(0)
提交回复
热议问题