#include "Iostream.h"
class _print
{
public:
_print& operator , (const char* s) { cout << s; return *this; }
} Print;
int main()
{
Print, "Hello", "World";
return 0;
};
Isn''t that a cool little tidbit? Can''t think of a real use for it, though...
farmersckn
How Cool Is This!?
run this program:
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Syntactical ease is one use I can think of. The reason why no one uses it is that operators have a tendency to hide code, and this probably scares quite a few organized coders.
VK
March 21, 2001 06:52 AM
Why not just this instead:?
Hmm...thats whats called a function object, isn''t it?
#include class _Print{ public: void operator() ( const char* string ) { std::cout << string; }} Print;void main(){ Print("Hello world"); return 0;}
Hmm...thats whats called a function object, isn''t it?
Er...
Why not just use
#include "iostream.h"
int main(void) {
cout << "Hello World";
}
Is there really a need for all that complexity to print a string?![](smile.gif)
E
Edited by - Eight on March 21, 2001 7:57:53 AM
Why not just use
#include "iostream.h"
int main(void) {
cout << "Hello World";
}
Is there really a need for all that complexity to print a string?
![](smile.gif)
E
Edited by - Eight on March 21, 2001 7:57:53 AM
>> Print, "Hello", "World";
Looks kinda like you''re trying to turn C++ into BASIC. EVIL!!
-Ironblayde
Aeon Software
Down with Tiberia!![](http://www.aeon-software.com/misc/notiberia.gif)
"All your women are belong to me." - Nekrophidius
Looks kinda like you''re trying to turn C++ into BASIC. EVIL!!
![](smile.gif)
-Ironblayde
Aeon Software
![](http://www.aeon-software.com/misc/notiberia.gif)
![](http://www.aeon-software.com/misc/notiberia.gif)
"All your women are belong to me." - Nekrophidius
"Your superior intellect is no match for our puny weapons!"
LOL ![](smile.gif)
I ran across the sequencing operator in my C++ book lately, too. Anybody found a really good use for this?
![](smile.gif)
I ran across the sequencing operator in my C++ book lately, too. Anybody found a really good use for this?
I''d say there''s no _painless_ use for it. But imagine this:
You need to define a set of objects, and each object has to update its data to reflect its neighbor. For example, you could use this to define a linked list with the sequencing operator...much clearer than when you use function calls. But as any overloaded operator, it''s a syntactical nightmare.
You need to define a set of objects, and each object has to update its data to reflect its neighbor. For example, you could use this to define a linked list with the sequencing operator...much clearer than when you use function calls. But as any overloaded operator, it''s a syntactical nightmare.
VK
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement