opIndex operators
    gedaiu 
    szabobogdan at yahoo.com
       
    Sat Apr 13 02:52:51 PDT 2013
    
    
  
Hi again!
I don't understand why we have opIndex() and opIndexAssign()... 
can anyone explain this for me?
Because in c++ there is only one operator overload for "[]" and 
it looks like this:
Value& Value::operator[] (constValue offset) {
	return container[offset];
}
and with this operator overload I can set or get values from 
container, and also easily implement custom multilevel arrays.
In D when I have this method
Value& opIndex(Value index) {
	return container[index];
}
I get this error.
Error: no identifier for declarator Value
Error: semicolon expected, not '&'
Declaration expected, not '&'
And also, how you can implement custom structs that acts like a 
multilevel array in D like in c++?
Thanks!
    
    
More information about the Digitalmars-d-learn
mailing list