| penny9key (12) | |
|
Hey guys I have this class of books that has two strings and I want to overload the "<" so that it checks firstly the book names and then the book authors String _author String _bookname the thing is i have no idea how the eqution would look like but im pretty sure I should use ".compare" Thanks! | |
|
|
|
| ne555 (4038) | |
|
Get a deck of cards. Sort it according to the suit (clubs, hearts, spades, diamonds) and value (A to K) Understand what you did Translate that knowledge | |
|
|
|
| penny9key (12) | |||||
so it goes something like this:
Im not sure its the right way to behave tho I tried this and seems to be working, but is this correct usage...
| |||||
|
Last edited on
|
|||||
| mukomo (27) | |
|
Hmm... for overloading the < operator, it seems that the second code snippet is actually incorrect, simply because it's possible that _surname>o._surname. Same with name. It would be easily fixed by changing !=0 to <0. Also, when you want to overload the < operator, how are you defining a<b? | |
|
|
|
| penny9key (12) | |
| im looking for same for same autho and then if they mismatch ie not eual since im comparing strings i go to the next one and check if they mismatch etc | |
|
|
|