Connecting Tech Pros Worldwide Forums | Help | Site Map

Calling a object's overloaded operator with a pointer to that object.

matt p
Guest
 
Posts: n/a
#1: Jul 22 '05
example:
FunClass myfun;
FunClass *lotsofunptr=&myfun;

myfun[string]; //calls the overloaded [] operator;


lotsofunptr->[string];//error

help is much apreciated
Karthik Kumar
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Calling a object's overloaded operator with a pointer to that object.


matt p wrote:[color=blue]
> example:
> FunClass myfun;
> FunClass *lotsofunptr=&myfun;
>
> myfun[string]; //calls the overloaded [] operator;[/color]

How does your signature of the overloaded function look like ?
And what is 'string' . C++ std. specifies it to be a type in std
namespace.
[color=blue]
>
>
> lotsofunptr->[string];//error
>[/color]

Post compilable code here to seek help.

--
Karthik. http://akktech.blogspot.com .
'Remove _nospamplz from my email to mail me.'
Karthik Kumar
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Calling a object's overloaded operator with a pointer to that object.


Karthik Kumar wrote:[color=blue]
> matt p wrote:
>[color=green]
>> example:
>> FunClass myfun; FunClass *lotsofunptr=&myfun;
>>
>> myfun[string]; //calls the overloaded [] operator;[/color][/color]

Assuming string to be a variable, (a bad choice for naming it
though) and of the same type as the overloaded function would expect ,
here it goes.

myfun[string] ;

is essentially

myfun.operator[](string)


[color=blue]
>
>
> How does your signature of the overloaded function look like ?
> And what is 'string' . C++ std. specifies it to be a type in std
> namespace.
>[color=green]
>>
>>
>> lotsofunptr->[string];//error[/color][/color]

So if you want to get the same thing as that of a pointer , use

(*lotsofunptr)[string];

You essentially dereference the pointer and apply the same syntax.
If you are not happy then use

lotofunptr->operator[](string)

That should work fine too.

[color=blue][color=green]
>>[/color]
>
> Post compilable code here to seek help.
>[/color]


--
Karthik. http://akktech.blogspot.com .
'Remove _nospamplz from my email to mail me.'
Julián Albo
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Calling a object's overloaded operator with a pointer to that object.


matt p wrote:
[color=blue]
> example:
> FunClass myfun;
> FunClass *lotsofunptr=&myfun;
>
> myfun[string]; //calls the overloaded [] operator;
>
>
> lotsofunptr->[string];//error[/color]

(* lotsofunptr) [string];

lotsofunptr->operator [] (string);

--
Salu2
Closed Thread