Results 1 to 13 of 13

Thread: [Resolved] Overloaded Operators

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] Overloaded Operators

    I'm trying to create some operators for my class, but get errors:

    Code:
    public static CMovieList operator<(CMovieList c) {
    
    }
    It says "Overloadable unary operator expected." How, then, do I do a binary operator?
    Last edited by The Hobo; Sep 13th, 2003 at 08:48 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yes, it did, thanks.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Okay, maybe not. I still don't understand. I read that, then tried this:

    Code:
    public static bool CMovieList operator<(CMovieList a, CMovieList b) {
        return a.AmountMade < b.AmountMade;
    }
    
    'and:
    
    public static CMovieList operator>(CMovieList a, CMovieList b) {
        return a.AmountMade > b.AmountMade;
    }
    And got a trunk full of errors.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You have to return a CMoveList object.

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    What are the errors? Should'nt you be return either true or false?

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by DevGrp
    What are the errors? Should'nt you be return either true or false?
    I am at home now, so I can't compile it and give you the errors. I am returning true or false (unless that gives off different values).

    Lethal, I'll give it a try Monday when I'm on campus again and, if I can't get it working, I'll post the errors.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I agree with DevGrp, you should be returning a bool, when I replied, I didn't look at the operator (I should have.. ), although what I pointed out is also correct..

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Am I not returning a bool?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Okay, now that I'm home and have a free moment, I pulled out my C# book for the class I'm taking (I didn't have it when I was at school), and it says this:

    Code:
    public static bool operator <(ClassName op1, ClassName op2) {
        return (op1.value <= op2.value);
    }
    Isn't that pretty much what I'm doing?

    I really wish I had VS.Net here at home so I could work on these things, but I have to finish building my PC before I can install it...and since I'm broke, that's going to be awhile.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Look here, you have CMovieList after bool:

    Code:
    public static bool CMovieList operator>(CMovieList a, CMovieList b) {
        return a.AmountMade > b.AmountMade;
    }
    You dont need that..

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Okay...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    That did it. Thanks for your time.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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