Click to See Complete Forum and Search --> : Overloading the << operator
bmxouch2
October 28th, 2002, 09:37 PM
This is driving me nuts. Ok, here is the deal, I'm just playing around with some code... and something that should be absolutely easy, is not working.
Here is my prototype:
ostream& operator<<(ostream&, Fraction&);
.NET is saying that there are too many args... I don't get it.
Any help would be cool.
Peace all
dimm_coder
October 31st, 2002, 03:41 AM
May be U declare this like method for Function class??? So it's incorrect. If no, write more code.
This works fine:
#include <iostream.h>
class Foo
{
friend ostream & operator << ( ostream & cout, Foo& f );
private:
int n;
public:
Foo ( int _n ) : n(_n) {}
};
ostream & operator << ( ostream & cout, Foo& f ) { return cout << f.n << endl; }
int main(int argc, char* argv[])
{
Foo f(999);
cout << f;
return 0;
}
bmxouch2
October 31st, 2002, 12:28 PM
Sorry everyone, I thought I deleted this post. I did figure it out.... I don't know what I was thinking, but I was trying to declare the function as a member function, forgot that you couldnot do that with the bitshift operators. Oh well. Thanks anyway. Late
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.