Error E2235 in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lintwurm
    New Member
    • Sep 2008
    • 7

    Error E2235 in c++

    Hello. I wonder of anyone can help me.

    I am trying to overload some operators, but it keeps giving me some problems...

    I used the same code in another program and it works fine!!!

    here is the coding that is giving me grief...



    bool Chromosome::ope rator == (const Chromosome& other) const
    {
    return ((fitness == other.fitness() ));
    }

    bool Chromosome::ope rator < (const Chromosome& other) const
    {
    return ((fitness < other.fitness() ));
    }

    bool Chromosome::ope rator > (const Chromosome& other) const
    {
    return ((fitness > other.fitness() ));
    }

    bool Chromosome::ope rator <= (const Chromosome& other) const
    {
    return ((fitness <= other.fitness() ));
    }

    bool Chromosome::ope rator >= (const Chromosome& other) const
    {
    return ((fitness >= other.fitness() ));
    }




    Thank you very much for your time...

    Very much appreciated
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    Originally posted by Lintwurm
    it keeps giving me some problems...
    What problems? Error messages? Run-time errors?

    Comment

    • Lintwurm
      New Member
      • Sep 2008
      • 7

      #3
      Originally posted by scruggsy
      What problems? Error messages? Run-time errors?
      It doesn't compile at all...

      This is the error message:
      "Error E2235 Chromosome.cpp 51: Member function must be called or its address taken in function Chromosome::ope rator ==(const Chromosome &) const"

      Thank you for your help in advance

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        Originally posted by Lintwurm
        It doesn't compile at all...

        fitness == other.fitness()
        As fitness is a member function ( i suppose ), you should call it for 'this' instance with () as you do it for 'other':

        fitness() == other.fitness()

        Comment

        • Lintwurm
          New Member
          • Sep 2008
          • 7

          #5
          Originally posted by newb16
          As fitness is a member function ( i suppose ), you should call it for 'this' instance with () as you do it for 'other':

          fitness() == other.fitness()

          Thanks!!! Finally I can continue =)

          Comment

          Working...