jeudi 4 août 2016

class array, cast pointer in operator[]

In my library I've an array class:

template < class Type >
class Array
{ 
Type* array_cData;
...
Type& operator[] (llint Index)
    {
        if (Index >= 0 && Index < array_iCount && Exist())
            return array_cData[Index];
    } 
};

And that's nice, but if I've generated in the stack the class like:

Array<NString>* space = new Array<NString>(strList->toArray());
checkup("NString split", (*space)[0] == "Hello" && (*space)[1] == "world");
//I must get the object pointed by space and after use the operator[]

So my question is: I can get the object in array_cData without specify object pointed like this:

Array<NString>* space = new Array<NString>(strList->toArray());
checkup("NString split", space[0] == "Hello" && space[1] == "world");

Thanks in advance! :3

-Nobel3D

Aucun commentaire:

Enregistrer un commentaire