logic help

Discussion in 'OT Technology' started by Stemby, Nov 7, 2005.

  1. Stemby

    Stemby Whoooose House? COOOOOOOOOOOOGS HOUSE!

    Joined:
    Sep 16, 2004
    Messages:
    3,465
    Likes Received:
    0
    Location:
    Houston,Tx
    this is c++ i need to do a check on a set "cars on a train"

    part of a class. I think i am over thinking this just a bit

    PHP:
    bool Train::operator==(const TrainA) const
     { 
         if (
    maxWagons == A.maxWagons)
             for(
    int i 0;i<maxWagons;i++)
                 if( 
    wagonptr[i] != A.wagonptr[i])
                     return 
    false;
                 else if (
    i==maxWagons)
                     return 
    true;            
                 else
                     continue;
         return 
    false;
     }
     
    bool Train::operator!=(const TrainA) const
     { 
         if (
    maxWagons == A.maxWagons)
             for(
    int i 0;i<maxWagons;i++)
                 if( 
    wagonptr[i] != A.wagonptr[i] )
                     return 
    false;
                 else
                     return 
    true;
     
         return 
    true;
    PHP:
    bool Wagon::operator==(const WagonA) const

        if( 
    tons == A.tons && kind == A.kind )
            return 
    true;
        return 
    false;
    }
    bool Wagon::operator!=(const WagonA) const

        if( 
    tons == A.tons && kind == A.kind )
            return 
    false;
        return 
    true;
    }
    o yea i'm over loading the == and != if you didn't catch it
     
  2. Deevan

    Deevan Active Member

    Joined:
    Jul 12, 2005
    Messages:
    11,720
    Likes Received:
    0
    Location:
    Orlando, FL USA Posts: 4

    What are you trying to accomplish? I can't understand. :(

    Either way you're going to need to add some comments in your code for a good score.
     
  3. Deevan

    Deevan Active Member

    Joined:
    Jul 12, 2005
    Messages:
    11,720
    Likes Received:
    0
    Location:
    Orlando, FL USA Posts: 4
    Wait, are you trying to set an object class equal to the contents of an instance? That doesn't work...
     
  4. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    please post all of your code
     
  5. peerk

    peerk New Member

    Joined:
    Mar 14, 2005
    Messages:
    984
    Likes Received:
    0
    I can't comment on the correctness of the code, but I believe once you get the overloaded "==" working for each train and wagon you can use it to do "!=". By doing something like:

    return !(thingA == thingB);

    I haven't worked with c++ classes in awhile but I remember doing something similar.
     

Share This Page