[osg-users] Why not const pointers in array setters

Robert Osfield robert.osfield at gmail.com
Mon May 29 11:31:21 PDT 2017


Hi Bruno,

On 29 May 2017 at 13:42, Bruno Oliveira <bruno.manata.oliveira at gmail.com> wrote:
> in array setters, for instance in osg::Geometry::setVertexArray, why is the
> array argument non-const?

osg::Geometry takes/shares ownership of the array you pass in so it's
free to delete, modify it, or other parts of the OSG/your application
are free to modify it, so it can't enforce that the array you pass in
is const.  If you can't enforce it being const that having a const
input would be misleading.

> How bad is it that I const_cast an array of my into a Geometry?

It's not bad, unless your application relies on no other part of the
OSG/your application modifying that array so actually intend it to be
fully const.  Hopefully it will flag up that fact that the assumptions
you might have been previously making might no longer hold.

Robert.



More information about the osg-users mailing list