Overloading the () operator
-
I don't see any need of irony for a perfectly legitimate question, nor I see any need of such an arrogant answer. See the next post [^]
2 bugs found. > recompile ... 65534 bugs found. :doh:
No irony and certainly not anywhere close to the amount of arrogance that seems to be in your post. Are you the posting police? Actually I was agreeing with the OP. I rarely see use of this that doesn't make the code harder to read than it would be if a meaningful-named method was used. Every time this comes up (function call operator) I'm reminded how lame the example is in the Visual C++ documentation:
"Given an appropriate overloaded function-call operator, however, this syntax
can be used to offset the x coordinate 3 units and the y
coordinate 2 units. The following code shows such a definition:"// function_call.cpp
class Point
{
public:
Point() { _x = _y = 0; }
Point &operator()( int dx, int dy )
{ _x += dx; _y += dy; return *this; }
private:
int _x, _y;
};int main()
{
Point pt;
pt( 3, 2 );
}Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I don't see any need of irony for a perfectly legitimate question, nor I see any need of such an arrogant answer. See the next post [^]
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
No irony and certainly not anywhere close to the amount of arrogance that seems to be in your post. Are you the posting police? Actually I was agreeing with the OP. I rarely see use of this that doesn't make the code harder to read than it would be if a meaningful-named method was used. Every time this comes up (function call operator) I'm reminded how lame the example is in the Visual C++ documentation:
"Given an appropriate overloaded function-call operator, however, this syntax
can be used to offset the x coordinate 3 units and the y
coordinate 2 units. The following code shows such a definition:"// function_call.cpp
class Point
{
public:
Point() { _x = _y = 0; }
Point &operator()( int dx, int dy )
{ _x += dx; _y += dy; return *this; }
private:
int _x, _y;
};int main()
{
Point pt;
pt( 3, 2 );
}Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
Every time this comes up (function call operator) I'm reminded how lame the example is in the Visual C++ documentation:
That one is lame, but there are others that are not[^].
-
Mark Salsbery wrote:
Every time this comes up (function call operator) I'm reminded how lame the example is in the Visual C++ documentation:
That one is lame, but there are others that are not[^].
Indeed. Thanks much for the link (and the wiki link) :) Seriously. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
emilio_grv wrote:
I don't see any need
Thanks, we'll be sure to check with you from now on. Get over yourself :zzz:
:laugh::laugh: Thanks, I appreciate. But, as you can see, that served as a prompt to the author to better explain is position. It's called "reverse psychology" It worked.
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
No irony and certainly not anywhere close to the amount of arrogance that seems to be in your post. Are you the posting police? Actually I was agreeing with the OP. I rarely see use of this that doesn't make the code harder to read than it would be if a meaningful-named method was used. Every time this comes up (function call operator) I'm reminded how lame the example is in the Visual C++ documentation:
"Given an appropriate overloaded function-call operator, however, this syntax
can be used to offset the x coordinate 3 units and the y
coordinate 2 units. The following code shows such a definition:"// function_call.cpp
class Point
{
public:
Point() { _x = _y = 0; }
Point &operator()( int dx, int dy )
{ _x += dx; _y += dy; return *this; }
private:
int _x, _y;
};int main()
{
Point pt;
pt( 3, 2 );
}Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
Are you the posting police?
Not at all. Just wanted to know the reasons of such a "taliban" position. Now I know. Like many MS MVP you're convinced MS documentations about languages is the Bible. I'm not. I consideri it as just one (of many) sources of information. And Nemania explained what it is for. Now, is your good example of A (better ONE) bad use, enough to say "never use" without any explanation about? I think no, but I couldn't say it, until you didn't provide any motivation about. Of course, fell free to sustain your position, but let every one else to know.
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
Indeed. Thanks much for the link (and the wiki link) :) Seriously. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
Thanks much for the link (and the wiki link) Seriously.
You're welcome. In this profession, we all learn all the time, and that's one thing I love about it :)
-
Mark Salsbery wrote:
Thanks much for the link (and the wiki link) Seriously.
You're welcome. In this profession, we all learn all the time, and that's one thing I love about it :)
I agree. Geez, if I didn't learn anything than hanging out at this site would be a complete waste of time :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery wrote:
Are you the posting police?
Not at all. Just wanted to know the reasons of such a "taliban" position. Now I know. Like many MS MVP you're convinced MS documentations about languages is the Bible. I'm not. I consideri it as just one (of many) sources of information. And Nemania explained what it is for. Now, is your good example of A (better ONE) bad use, enough to say "never use" without any explanation about? I think no, but I couldn't say it, until you didn't provide any motivation about. Of course, fell free to sustain your position, but let every one else to know.
2 bugs found. > recompile ... 65534 bugs found. :doh:
emilio_grv wrote:
Like many MS MVP you're convinced MS documentations about languages is the Bible.
Where did you get that from? You seem to have implied a lot of things from one line of tongue-in-cheek text that wasn't even directed to you. If I didn't post enough information or provide any help to you or the OP then simply ignore my post. I'm pretty sure all of us who read here do the same. If everyone starts pulling apart useless and bad posts here (and there are LOTS of them, every day), the forums will degenerate pretty quickly. If you knew the slightest thing about me, you'd know that me being an MS MVP is the real irony. I was dragged into using MS dev tools, kicking and screaming. I had no choice. I still have no choice. It's market and customer demand. I do have a choice to not make money but I'm not choosing that yet. Until then, I will make the best of what I have to use, including whatever MS is kind enough to give me. And arrogance? Give me a break. I have never claimed to know everything, and have repeatedly stated I know next to nothing. I'm here on this site to learn and no other reason. I figure with 4 million+ users potentially able to contribute to a thread, I'm going to pick up some knowledge, and I do. If that stops, I will move on. Cheers :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
No irony and certainly not anywhere close to the amount of arrogance that seems to be in your post. Are you the posting police? Actually I was agreeing with the OP. I rarely see use of this that doesn't make the code harder to read than it would be if a meaningful-named method was used. Every time this comes up (function call operator) I'm reminded how lame the example is in the Visual C++ documentation:
"Given an appropriate overloaded function-call operator, however, this syntax
can be used to offset the x coordinate 3 units and the y
coordinate 2 units. The following code shows such a definition:"// function_call.cpp
class Point
{
public:
Point() { _x = _y = 0; }
Point &operator()( int dx, int dy )
{ _x += dx; _y += dy; return *this; }
private:
int _x, _y;
};int main()
{
Point pt;
pt( 3, 2 );
}Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
I actually use this all the time, in the XTrace.h file I include with some of my projects. I got the idea from this article. Very useful.
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]
-
I actually use this all the time, in the XTrace.h file I include with some of my projects. I got the idea from this article. Very useful.
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]
I only commented about the original context, because it reminded me of the bad example, and definitely didn't explain myself. Your example has a recognizable context, thus easy for me to read. Same with some examples in the other posted links. A POINT class with a function operator that takes two ints, and uses those ints to offset the POINT? Not very clear to me. Thanks Hans, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
yadrif wrote:
So, what is the purpose of oerloading the () operator
-
I only commented about the original context, because it reminded me of the bad example, and definitely didn't explain myself. Your example has a recognizable context, thus easy for me to read. Same with some examples in the other posted links. A POINT class with a function operator that takes two ints, and uses those ints to offset the POINT? Not very clear to me. Thanks Hans, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
To be completely honest, this TRACE example was the first one that I saw that made me realize how useful it could be. Like you, I had seen "academic" examples, but this one brought it home.
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]