Does return statement copy values

前端 未结 11 1821
夕颜
夕颜 2020-12-23 08:56

I am wondering about this because of scope issues. For example, consider the code

typedef struct {
    int x1;/*top*/
    int x2;/*bottom*/
    int id;
} sub         


        
11条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 09:41

    In your case , it will return a copy

    If your code was

    subline_t& subline(int, int)
    

    then it would return a reference, which would yield in undefined behaviour.

提交回复
热议问题