i have const-overloaded methods in class:
class a{ public: typedef int data[10]; data& operator[](int index); const data& operator[](int index) const; }
this class implementing copy-on-write internal data. figured since allowing access data directly, must create copy of shared data (if shared obviously) on every use of operator[]
, not operator[] const
. however, if code using operator[] reading data, object not declared const, still cause creating copy, operator[] used. there syntax let me allow choose of operators calling?
yes: const_cast<a const&>(anaobj)[5]
.
Comments
Post a Comment