#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0

    binary 'operator <<' has too many parameters


    Can anyone tell me what is wrong with these piece of code?

    ostream& operator<<(ostream& Out, const DiveLogPage& toWrite)


    Thanks ! :)
  2. #2
  3. Left due to despotic ad-min
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Posts
    1,044
    Rep Power
    14
    I'm guessing a fair bit, as your sample is incomplete.

    I'm guessing this is actually embedded in a class something like'

    class Foo
    {
    public:

    ostream& operator<<(ostream& Out, const DiveLogPage& toWrite) ;

    };

    which actually declares operator<< as a non-static member function of class Foo. As a non-static member function, this means the operator will accept an implicit "this" pointer i.e. the function effectively has three arguments.

    As to what you're trying to do, you probably intended something like;

    class DiveLogPage
    {
    public:

    friend ostream& operator<<(ostream& Out, const DiveLogPage& toWrite) ;
    };

    A friend function is not actually a member function, so does not have the hidden "this" pointer passed to it.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    3
    Rep Power
    0
    I think when you put a binary operator overload function inside a class it, in fact, only takes one argument.

    Try declaring this function outside any classes.

IMN logo majestic logo threadwatch logo seochat tools logo