c++ passing by const reference

前端 未结 4 2087
独厮守ぢ
独厮守ぢ 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:24

    Yes, body is constant. That means that no non-const member functions may be called, and no member variables be modified.

    Neither is being done. The only member of body used is body.bp[0], which is not changed either, but merely used to get at points, which might or might not be constant...

    Corrolary: Don't make data members public.

提交回复
热议问题