Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Calling a object's overloaded operator with a pointer to that object.

Reply
Thread Tools

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

 
 
matt p
Guest
Posts: n/a
 
      11-07-2004
example:
FunClass myfun;
FunClass *lotsofunptr=&myfun;

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


lotsofunptr->[string];//error

help is much apreciated
 
Reply With Quote
 
 
 
 
Karthik Kumar
Guest
Posts: n/a
 
      11-07-2004
matt p wrote:
> example:
> FunClass myfun;
> FunClass *lotsofunptr=&myfun;
>
> myfun[string]; //calls the overloaded [] operator;


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.

>
>
> lotsofunptr->[string];//error
>


Post compilable code here to seek help.

--
Karthik. http://akktech.blogspot.com .
'Remove _nospamplz from my email to mail me.'
 
Reply With Quote
 
 
 
 
Karthik Kumar
Guest
Posts: n/a
 
      11-07-2004
Karthik Kumar wrote:
> matt p wrote:
>
>> example:
>> FunClass myfun; FunClass *lotsofunptr=&myfun;
>>
>> myfun[string]; //calls the overloaded [] operator;


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)



>
>
> 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.
>
>>
>>
>> lotsofunptr->[string];//error


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.


>>

>
> Post compilable code here to seek help.
>



--
Karthik. http://akktech.blogspot.com .
'Remove _nospamplz from my email to mail me.'
 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      11-07-2004
matt p wrote:

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


(* lotsofunptr) [string];

lotsofunptr->operator [] (string);

--
Salu2
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Problem in calling an overloaded operator= from inside anotheroverloaded operator= Afshin C++ 7 08-16-2011 12:46 PM
Problem in calling an overloaded operator= from inside anotheroverloaded operator= in C++ Afshin C++ 0 08-12-2011 12:19 PM
Problem in calling an overloaded operator= from inside anotheroverloaded operator Afshin C++ 0 08-12-2011 12:01 PM
"overloaded cast operator" and "operator const" John Goche C++ 2 09-04-2006 02:48 PM



Advertisments