c++ passing by const reference

前端 未结 4 2052
独厮守ぢ
独厮守ぢ 2021-01-07 19:23

In the following program body cosists of a vector of pointers. Points is a struct of x,y,z coordinates and a point_id. I believe as body is passed by const reference, the fo

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 19:26

    This is one of best example which shows why data members should not be public.

    here, body is constant hence its data members must not be changed, but in body.bp[0]->points point is being changed which is not the member of Body.Hence no const violation.

提交回复
热议问题