Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Overload operator[] How ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Asger Jørgensen  
View profile  
 More options Mar 18 1999, 3:00 am
Newsgroups: borland.public.cpp.language
From: Asger Jørgensen <asge...@get2net.dk>
Date: 1999/03/18
Subject: Overload operator[] How ?
Hi there

Could someone please be so kind as to explain what i am doing wrong .

I am making a list class for use in a little card game and i want to
overload the [] operator.

In the .h file i do like this:

class TListt{
private:
   static TListt* Shared;
   int TheEnd;
   TCard** Lst;

protected:
public:

    //Other functions functions

   TCard* operator[] (unsigned Index) {return Lst[Index];}

   bool __fastcall AddShared();

};

in the .cpp file i have a function where i try to use the operator
but i recive the error that TListt can't be converted to TCard*
WHY ?? and how do i solve it ??

bool __fastcall TListt::AddShared()
{
   TCard* R = Shared[0]; //<<<<<<<<<<<<<<<<<<<

//........Snip

Thanks  in advance
    Asger
Asge...@get2net.dk


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Heiman  
View profile  
 More options Mar 18 1999, 3:00 am
Newsgroups: borland.public.cpp.language
From: "Scott Heiman" <hei...@gnt.net>
Date: 1999/03/18
Subject: Re: Overload operator[] How ?
Asger Jørgensen wrote in message <36F0E272.84B48...@get2net.dk>...

<snip>

Shared was declared as a TListt *.  Lst was declared as a TCard **.

So this

>   TCard* R = Shared[0]; //<<<<<<<<<<<<<<<<<<<

should be

  TCard* R = Lst[0];

or

  TListt &R = Shared[0];

BTW, this looks like Builder code.  You should post builder questions in the
newsgroups devoted to Builder (borland.public.cppbuilder.language).

--
Regards,
Scott
http://www.gnt.net/~heiman


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Asger Jørgensen  
View profile  
 More options Mar 18 1999, 3:00 am
Newsgroups: borland.public.cpp.language
From: Asger Jørgensen <asge...@get2net.dk>
Date: 1999/03/18
Subject: Re: Overload operator[] How ?
Hi Scott

Thanks for replying.

but i have overloaded the [] oprator like this :

    TCard* __fastcall operator[](unsigned Index){return Lst[Index];}

so i thought    Shared[0]    would return the first  TCard* from the
TListt   Lst
or have i misunderstood the thing about overloading?
I must edmit that i am new to the overload stuff.

> BTW, this looks like Builder code.  You should post builder questions in the
> newsgroups devoted to Builder (borland.public.cppbuilder.language).

It is but i thought that this was a C++ language question since it is
a simple class - no component stuff.

    Thanks again
         Asger
asge...@get2net.dk


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Heiman  
View profile  
 More options Mar 18 1999, 3:00 am
Newsgroups: borland.public.cpp.language
From: "Scott Heiman" <hei...@gnt.net>
Date: 1999/03/18
Subject: Re: Overload operator[] How ?
Asger Jørgensen wrote in message <36F0F304.FE480...@get2net.dk>...

<snip>

>but i have overloaded the [] oprator like this :

>    TCard* __fastcall operator[](unsigned Index){return Lst[Index];}

This is perfectly legitimate.  For example

TListt A;

TCard *B = A[1];

should work.

>so i thought    Shared[0]    would return the first  TCard* from the
>TListt   Lst

Shared[0] will return the first TListt object in the array pointed to by
Shared.

>or have i misunderstood the thing about overloading?

I think so.  The overloaded [] operator works for a TListt object as in the
example above; however,

TCard *B = Shared[0][0];

will do what you want.  This returns the first card in the first TListt
object.

>> BTW, this looks like Builder code.  You should post builder questions in
the
>> newsgroups devoted to Builder (borland.public.cppbuilder.language).

>It is but i thought that this was a C++ language question since it is
>a simple class - no component stuff.

OK, you're forgiven ;-)

--
Regards,
Scott
http://www.gnt.net/~heiman


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Asger Jørgensen  
View profile  
 More options Mar 19 1999, 3:00 am
Newsgroups: borland.public.cpp.language
From: Asger Jørgensen <asge...@get2net.dk>
Date: 1999/03/19
Subject: Re: Overload operator[] How ?
Hi Scott

Scott Heiman wrote:
> I think so.  The overloaded [] operator works for a TListt object as in the
> example above; however,

> TCard *B = Shared[0][0];

> will do what you want.  This returns the first card in the first TListt
> object.

Yeb! and thats where i went wrong, i almost only work with pointer
to objects so i newer thought about that Shared only was a pointer and
not the object.
So:

TCard *B = (*Shared)[0];

will do to, but both wayes kindof messes up elegant the syntaks so i will
probably see if i can figure out how to make a syntax like this:

TCard *B = Shared->Items[0];

if not i will use the standard function call:

TCard *B = Shared->Items(int Index);

Thanks again
    Asger
Asge...@get2net.dk


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google