I need some help here.

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Aug 31 12:41:52 PDT 2006

Damian wrote:
>>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.

Actually yes it could, as all members of the same module have implicit "friend" 
relationships.  So, since 'c1' and the wrapper class (which should probably be a nested 
class anyhow) would be in the same module, 'c1' would have access to the wrapper's private 
'data' field.

-- Chris Nicholson-Sauls

More information about the Digitalmars-d-learn mailing list