Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

operator overload of []

0 views
Skip to first unread message

Mark Bracey

unread,
Oct 29, 1998, 8:00:00 AM10/29/98
to
I want to overload [] in order to create the equivalent of an indexed
default property (object pascal term)

I have a class which is what I want to index

e.g.

TValue * operator [](int i) {return(TValue*)(FValueList->Items[i]););

FValueList is a TList

But when I try to do the assignment

TValue * Value

Value = List[i];

I get a compile error that 'List' of type TValueList cannot be assigned
to TValue.

What am I doing wrong?

Chris Uzdavinis (TeamB)

unread,
Oct 29, 1998, 8:00:00 AM10/29/98
to
Mark Bracey wrote:
> TValue * operator [](int i) {return(TValue*)(FValueList->Items[i]););

This looks correct.


> Value = List[i];


> What am I doing wrong?

It's just how you're using your list. Presumably, List is a pointer
to a TList, so what you really need to do is this:

Value = (*List)[i];

...to dereference the pointer, and then call the operator[] on the
object.

So you know why you got the error... the way you wrote it, your code
was trying to dereference the element number [i] in an array of
TLists. So the return value of that expression was a TList*, which
didn't match the TValue * type of "Value". :)
--
Chris (TeamB)

Mark Bracey

unread,
Oct 30, 1998, 8:00:00 AM10/30/98
to
Thank you very much. It's been awhile and have spent most of my time on
Delphi as of late.

Thanks again!

0 new messages