|
-
October 28th, 2002, 10:37 PM
#1
Overloading the << operator
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
-
October 31st, 2002, 04:41 AM
#2
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;
}
"UNIX is simple; it just takes a genius to understand its simplicity!"
-
October 31st, 2002, 01:28 PM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|