Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!mcnc!duke!macbeth!sk From: sk@macbeth.cs.duke.edu (Srinivasan Krishnan) Newsgroups: comp.lang.c++ Subject: detecting writes Keywords: arrays Message-ID: <21007@duke.cs.duke.edu> Date: 25 Jul 90 15:45:19 GMT Sender: news@duke.cs.duke.edu Lines: 36 While trying to implement an array based object, I have run into difficulties with detection of writes on the array. Here's part of the definition of the class: class IntArray { public : // allows assignments of the form A = B IntArray& operator=(const IntArray&); // returns the lvalue of the i-th element of the array int& operator[] (int); protected : // internal data representation int flag; int *ia; }; I would like to be able to set the variable "flag" to zero whenever any assignments are made to the array. Assignments to an array are of 2 types : 1 A = B ; ( A and B IntArrays ) By overloading the = operator , I am able to set the flag of A to 0 2 A[i] = somevalue; This is causing the problem. The [] operator is used for both reads and writes, and the = operator operates on integers. Is there any way I can cause the side effect of setting flag to 0 only on memory writes while retaining the use of the [] operator?