Featured post
c++ - Lazy evaluation and problems with const correctness -
i have made opengl camera class uses lazy evaluation provide final projection or model-view-projection matrices through getter functions. user provides various camera parameters throughout life of instance (fov, position, etc. ), rather have projection matrix and/or mvp matrix recalculated every time parameter changed, 'changed' flag set (i.e. old cached matrix invalid). whenever user requests updated final matrix, recalculated, result cached, , const reference returned.
everything sounds fine until call my:
const qmatrix4x4& oe_glcamera::getmodelviewprojection() const;
function const oe_glcamera instance... use const references everywhere in app extract camera data cad viewports without changing camera, getter function performs lazy evaluation on member variables if invalid - therefore breaking const-correctness.
is there language feature or design paradigm i'm unaware of this? or lazy evaluation fundamentally incompatible const-correctness? aware of const_cast<>, have never used myself have read few things boil down to: if have use it, have gone wrong somewhere. or saviour?
any advice greatfully received, cam
is there language feature or design paradigm i'm unaware of this?
perhaps, mutable
?
a member of class marked mutable
non-const
if accessed via reference or pointer owning class const
reference or pointer const
.
- Get link
- X
- Other Apps
Comments
Post a Comment