CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    17

    Angry 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

  2. #2
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    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!"

  3. #3
    Join Date
    May 2002
    Posts
    17
    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
  •  





Click Here to Expand Forum to Full Width

Featured