Jump to content
  • Advertisement

Archived

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

farmersckn

How Cool Is This!?

This topic is 6331 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
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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!