I need some help here.
Damian
damian.pop at gmail.com
Thu Aug 31 08:47:08 PDT 2006
>
> class MyArray(T) {
> private T[] _data;
>
> T opIndexAssign(uint index, T value) {
> notifyThatDataHasChanged();
> return _data[index] = value;
> }
>
> T opIndex(uint index) {
> return _data[index];
> }
> ...
> }
>
> This means that you can use your class's opIndex for something else.
> Alternatively, you could use this interface to return an immutable
> version of _data, just by not supporting opIndexAssign.
>
I would have to use
MyArray!(MyArray!(char)) _data;
for _data to be really immutable.
Anyway, I can't do this that way, since my class "cl" couldnt modify
_data either.
I think I will do something like this:
private:
char[][] _data;
int _maxDataLength;
public:
/** _DO NOT_ modify data this way, use "void data(char[][] d)" */
char[][] data(){
_return data;
}
void data(char[][] d){
_maxDataLength = calculateMaxDataLength(d);
_data = d;
}
More information about the Digitalmars-d-learn
mailing list