|
-
Sep 12th, 2003, 12:03 PM
#1
Thread Starter
Stuck in the 80s
[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.
-
Sep 12th, 2003, 12:10 PM
#2
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Sep 12th, 2003, 12:13 PM
#3
Thread Starter
Stuck in the 80s
-
Sep 12th, 2003, 12:19 PM
#4
Thread Starter
Stuck in the 80s
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.
-
Sep 12th, 2003, 12:52 PM
#5
PowerPoster
You have to return a CMoveList object.
-
Sep 12th, 2003, 01:12 PM
#6
Frenzied Member
What are the errors? Should'nt you be return either true or false?
-
Sep 12th, 2003, 01:17 PM
#7
Thread Starter
Stuck in the 80s
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.
-
Sep 12th, 2003, 02:22 PM
#8
PowerPoster
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..
-
Sep 12th, 2003, 03:14 PM
#9
Thread Starter
Stuck in the 80s
Am I not returning a bool?
-
Sep 12th, 2003, 03:17 PM
#10
Thread Starter
Stuck in the 80s
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.
-
Sep 12th, 2003, 05:24 PM
#11
PowerPoster
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..
-
Sep 12th, 2003, 10:44 PM
#12
Thread Starter
Stuck in the 80s
-
Sep 13th, 2003, 08:43 PM
#13
Thread Starter
Stuck in the 80s
That did it. Thanks for your time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|