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

M

matt p

example:
FunClass myfun;
FunClass *lotsofunptr=&myfun;

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


lotsofunptr->[string];//error

help is much apreciated
 
K

Karthik Kumar

matt said:
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.
 
K

Karthik Kumar

Karthik said:
matt said:
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.
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

matt said:
example:
FunClass myfun;
FunClass *lotsofunptr=&myfun;

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


lotsofunptr->[string];//error

(* lotsofunptr) [string];

lotsofunptr->operator [] (string);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top