Advertisement

How Cool Is This!?

Started by March 19, 2001 06:52 PM
7 comments, last by farmersckn 23 years, 10 months ago
run this program:

#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
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
Advertisement
Why not just this instead:?
#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?

E


Edited by - Eight on March 21, 2001 7:57:53 AM
Why not just use

%echo Hello World!
Why don''t you try it like this: Hello world
Advertisement
>> Print, "Hello", "World";

Looks kinda like you''re trying to turn C++ into BASIC. EVIL!!

-Ironblayde
 Aeon Software

Down with Tiberia!
"All your women are belong to me." - Nekrophidius
"Your superior intellect is no match for our puny weapons!"
LOL

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.
VK

This topic is closed to new replies.

Advertisement