Use of the & operator in C++ function signatures

后端 未结 9 970
刺人心
刺人心 2020-11-29 00:36

I\'m currently reading through Accelerated C++ and I realized I don\'t really understand how & works in function signatures.

int* ptr=#
         


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 01:14

    It's a reference which allows the function to modify the passed string, unlike a normal string parameter where modification would not affect the string passed to the function.

    You will often see a parameter of type const string& which is done for performance purposes as a reference internally doesn't create a copy of the string.

提交回复
热议问题