Pass a dynamic array of objects to function

前端 未结 3 2017
说谎
说谎 2021-01-06 16:58

I am in the process of learning c++. So i know a method by which you send something to function and then work as if it was call by value but actually it is call by reference

3条回答
  •  走了就别回头了
    2021-01-06 17:37

    Arrays are by default converted to pointers, which are then passed as reference. So, there is no provision for explicitly passing arrays by reference. That is,

    void list_cities(int number, City &p[])
    

    is not p[] being passed as reference, but makes p[] an array of references.

    Code:

    void list_cities(int number, City p[])
    {
        for(int i=0; i

提交回复
热议问题