I'm trying to create some operators for my class, but get errors:
It says "Overloadable unary operator expected." How, then, do I do a binary operator?Code:public static CMovieList operator<(CMovieList c) {
}
Printable View
I'm trying to create some operators for my class, but get errors:
It says "Overloadable unary operator expected." How, then, do I do a binary operator?Code:public static CMovieList operator<(CMovieList c) {
}
Yes, it did, thanks.
Okay, maybe not. I still don't understand. I read that, then tried this:
And got a trunk full of errors.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;
}
You have to return a CMoveList object.
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).Quote:
Originally posted by DevGrp
What are the errors? Should'nt you be return either true or false?
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.
I agree with DevGrp, you should be returning a bool, when I replied, I didn't look at the operator (I should have..:rolleyes: ), although what I pointed out is also correct..
Am I not returning a bool?
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:
Isn't that pretty much what I'm doing? :confused:Code:public static bool operator <(ClassName op1, ClassName op2) {
return (op1.value <= op2.value);
}
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. :(
Look here, you have CMovieList after bool:
You dont need that..Code:public static bool CMovieList operator>(CMovieList a, CMovieList b) {
return a.AmountMade > b.AmountMade;
}
Okay...
That did it. Thanks for your time.