Operator not found for the type

Discussion in 'C++' started by Ian Collins, Mar 1, 2007.

  1. Ian Collins

    Ian Collins Guest

    The Cool Giraffe wrote:
    > I tried to define an overloader for the operator <<. My source
    >
    > code is great except the stupid compiler doesn't get it. :)
    >
    >
    >
    > std::eek:stream& Particle::eek:perator<< (Particle& part) {
    >
    > std::eek:stream* ost = NULL;
    >
    > (*ost) << "diffusion particle";
    >
    > return (*ost); }
    >
    >
    > The error message is
    > error C2679: binary '<<' : no operator found which takes a right-hand
    > operand of type 'Particle' (or there is no acceptable conversion)
    > What did i do unsmartly?
    >

    Don't make the operator a member function, use

    std::eek:stream& operator<<( std::eek:stream&, const Particle& ) {..}

    --
    Ian Collins.
     
    Ian Collins, Mar 1, 2007
    #1
    1. Advertising

  2. I tried to define an overloader for the operator <<. My source

    code is great except the stupid compiler doesn't get it. :)



    std::eek:stream& Particle::eek:perator<< (Particle& part) {

    std::eek:stream* ost = NULL;

    (*ost) << "diffusion particle";

    return (*ost); }


    The error message is
    error C2679: binary '<<' : no operator found which takes a right-hand
    operand of type 'Particle' (or there is no acceptable conversion)
    What did i do unsmartly?

    --
    Vänligen Kerstin Viltersten
    (The Cool Giraffe)
     
    The Cool Giraffe, Mar 1, 2007
    #2
    1. Advertising

  3. Ian Collins

    Ron Natalie Guest

    Ian Collins wrote:
    > The Cool Giraffe wrote:
    >> I tried to define an overloader for the operator <<. My source
    >>
    >> code is great except the stupid compiler doesn't get it. :)
    >>
    >>
    >>
    >> std::eek:stream& Particle::eek:perator<< (Particle& part) {
    >>
    >> std::eek:stream* ost = NULL;
    >>
    >> (*ost) << "diffusion particle";
    >>
    >> return (*ost); }
    >>
    >>
    >> The error message is
    >> error C2679: binary '<<' : no operator found which takes a right-hand
    >> operand of type 'Particle' (or there is no acceptable conversion)
    >> What did i do unsmartly?
    >>

    > Don't make the operator a member function, use
    >
    > std::eek:stream& operator<<( std::eek:stream&, const Particle& ) {..}
    >

    It's not the source of the compile error, but he also is dereferencing
    a null pointer for unexplained reasons.
     
    Ron Natalie, Mar 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    7
    Views:
    9,574
    Scott M.
    Jun 9, 2004
  2. William Parker
    Replies:
    1
    Views:
    3,096
    Martin
    Jun 27, 2004
  3. Replies:
    3
    Views:
    557
  4. Replies:
    29
    Views:
    35,101
  5. Martin T.
    Replies:
    7
    Views:
    820
    Martin T.
    Mar 10, 2008
Loading...

Share This Page