• Advertisement

Archived

This topic is now archived and is closed to further replies.

How Cool Is This!?

This topic is 6146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
>> 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

Share this post


Link to post
Share on other sites
LOL

I ran across the sequencing operator in my C++ book lately, too. Anybody found a really good use for this?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement