Overloading operators. 5.5 hour till assignment due.

Started by
33 comments, last by Evil-Prey 22 years, 4 months ago
Ok I understand how to overload functions and how to do some overloading of operators but IM lost on this one. friend ostream& operator<<(ostream&, twoDimArray&); What are all the &? and what does this mean? Any help will be appreciated
If at first you don't suceed do something easier!.
Advertisement
Maybe you should look that up in your computer class''s reference .
*stifles laugh*

"So crucify the ego, before it''s far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that''s imagined and all conceivable."
- Tool

"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
Hey Hey Thanks for the non help moderator man. Go spread your advice somewhere else.
BEsides it not my assignment Im doing it as a favor.
I can''t find a clear explanation on how to overload ostream operators.
Where do they pick up these moderators? Can I be one?! Im good at being an asshole!!
If at first you don't suceed do something easier!.
For crying out loud, Stoffel. If you know the answer, then answer it. If you don''t, then ignore the thread. I''m so tired of the negativity on this forum -- everyone''s a smartass. Oh well.

To answer the question, a variable with a ''&'' in front of it (usually) is a reference. A reference is basically an alias for another vairable. You create the reference, assign it to the variable, and anything you do to the reference will affect the original variable as well. In this case, if you were to pass a variable to this function, it would create a reference to the variable of the type ''ostream'' or ''twoDimArray'', and anything you do to these references will affect the original variable.

Be careful, though, because ''&'' is also the "address of" operator. In other words, this:

int y = 3;
int x = &y

will assign the adress of ''y'' to ''x.'' How do you know the difference between a reference and an "address of"? Context. In the case of that function you''re having trouble with, it is a reference.

References are a bit difficult to explain in a few paragraphs, and you''re probably a bit confused. I would recommend checking out the topics of "References" and "Passing by Reference" in any of the books you have for more in-depth information.
quote:Original post by Evil-Prey
Hey Hey Thanks for the non help moderator man. Go spread your advice somewhere else.

You don''t get it. That''s your fault.

quote:BEsides it not my assignment Im doing it as a favor.

If whoever you''re doing it for can''t figure it out or learn by themselves, they don''t deserve to pass. Doing someone''s assignment for them is a disservice to them, so that wont make us better disposed towards you.

quote:I can''t find a clear explanation on how to overload ostream operators.

You can''t read, you can''t search and you can''t think. What else is new?

quote:Where do they pick up these moderators? Can I be one?! Im good at being an asshole!!

Actually, you''re no good. (And you''re not smart either). The hint was the term "reference." Try looking it up.

Start Here!
Ok. I understand the reference part. I didn''t realize those were references. I just started to do overloaded operators.
Thanks
If at first you don't suceed do something easier!.
::slaps forehead::

I just understood Stoffel''s joke. Hehe. You still should have answered the damned question, though. :p
---signature---People get ready.I'm ready to play.
I sense an aura of great assholeness eminating from this thread. Thanks guys for being so caring. If you want to help thanks any other advice is not needed.
If at first you don't suceed do something easier!.
quote:Original post by Anonymous Poster
For crying out loud, Stoffel. If you know the answer, then answer it. If you don''t, then ignore the thread. I''m so tired of the negativity on this forum -- everyone''s a smartass. Oh well.

Let''s put it like this, do you think someone who doesn''t understand references should be overloading istream operators?

''Nuff said.

Btw, & is always the address-of operator; what do you think an alias really is (that''s just drivel they tell newbies so that they don''t get confused). Passing by reference is passing the address rather than trying to pass a copy.

Start Here!

This topic is closed to new replies.

Advertisement