Overloading function operator ()
-
I agree with you, no need to overload curly brackets.
Still Alive!!! Thank you God.
Mr.Prakash wrote: I agree with you, no need to overload curly brackets Two words: Function Objects ;P :-)
Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell
-
Can we overload the function operator () - Curly brackets ? If yes then what would be the syntax for this.
If you mean
{}
then no, because they are not operators. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ Laugh it up, fuzzball. -
Mr.Prakash wrote: I agree with you, no need to overload curly brackets Two words: Function Objects ;P :-)
Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell
humm??? I lookedup in MSDN and it should be links for JScript.. As far as my knowldge Brase brackets are not operators so you cant overload it. brase brackets is used by the compiler for scope management of the identifiers.
Still Alive!!! Thank you God.
-
humm??? I lookedup in MSDN and it should be links for JScript.. As far as my knowldge Brase brackets are not operators so you cant overload it. brase brackets is used by the compiler for scope management of the identifiers.
Still Alive!!! Thank you God.
STL uses it all the time: they are called 'functors'. Search MSDN or Google for functors and you'll understand what I mean. Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
-
humm??? I lookedup in MSDN and it should be links for JScript.. As far as my knowldge Brase brackets are not operators so you cant overload it. brase brackets is used by the compiler for scope management of the identifiers.
Still Alive!!! Thank you God.
Right: You can overload normal parenthesis, being (), which is what I think the original poster really meant. You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.)
Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell
-
Right: You can overload normal parenthesis, being (), which is what I think the original poster really meant. You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.)
Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell
Ian Darling wrote: You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.) Or thunks (for the Smalltalk 80 perverted people :rolleyes:) -- So let's just walk from place to place, as long as we don't talk face to face.
-
Ian Darling wrote: You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.) Or thunks (for the Smalltalk 80 perverted people :rolleyes:) -- So let's just walk from place to place, as long as we don't talk face to face.
-
No I mean for parenthesis (). This has been asked to me during an interview. Can we overload function operator () ? If yes then how and in what scenario this would be required.
class multiplier
{
public:
int operator()(int i) { return i * 3; }
};multiplier mul;
cout << mul(10); // should return 30Robert-Antonio "Life is very hard, when you apply E-R model to it."
-
No I mean for parenthesis (). This has been asked to me during an interview. Can we overload function operator () ? If yes then how and in what scenario this would be required.
With all due respect, are you blind? Did you not see the first response to your query? -- So let's just walk from place to place, as long as we don't talk face to face.
-
class multiplier
{
public:
int operator()(int i) { return i * 3; }
};multiplier mul;
cout << mul(10); // should return 30Robert-Antonio "Life is very hard, when you apply E-R model to it."