c++ passing by const reference -
in following program body cosists of vector of pointers. points struct of x,y,z coordinates , point_id. believe body passed const reference, following step should produce error. program running without problem. can please explain me why this.
void readoutfile(const body& body, int n){ .... body.bp[0]->points.push_back(point_id(p,i)); }
here's issue:
body.bp[0]->points.push_back(point_id(p,i)); ^^
indirecting through pointer removes constness; rather, constness of result dependent on type of pointer.
t *t; // pointer t: can modify t , (*t) const t *t; // pointer const-t: can modify t not (*t) t *const t; // const-pointer t: can modify (*t) not t const t *const t; // const-pointer const-t: can't modify either t or (*t)
Comments
Post a Comment