LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Questions about custom C++ string class. (https://www.linuxquestions.org/questions/programming-9/questions-about-custom-c-string-class-356165/)

lowpro2k3 08-23-2005 11:03 AM

Questions about custom C++ string class.
 
I'm writing a C++ string class, and I've come pretty far with it. I've implemented copy constructors and assignment operators for both C-style string parameters and my own class object parameters, overloaded all the operators I can think of (except sidenote, see below), my destructor works, and I've implemented a few trivial <string.h> style functions like strlen, strcat. I think I'm going to add strcmp which I just thought of now.

About the operators, I'm a little puzzled on these ones: <, >, <=, >=. I've been thinking out the logic, and I don't know which of these strings would be 'less than' the other.

char * x = "Hello World";
char * y = "Hello World ";

If I overload the operators I listed, which string would be the lesser string, x or y? Obviously 'A' < 'B', but I run into problems when string are of different length.

Anyways, that should take less than a few hours and after that I'm starting to run out of ideas. This is one of the nicer classes I've written so I would like to continue on with it if I can think of ideas that interest me. I've thought about writing 'toFile' methods, but this seems a little pointless to me seeing how each object contains only one string. Opinions? If I cant think of anymore ideas I might start a new class, I'm thinking I might write an array class because I learned alot writing this string class. I would like to keep extending this class though especially if I hear more ideas.

Thanks,

- lowpro2k3

geeman2.0 08-23-2005 12:06 PM

Generally speaking a string is less than another string if it appears before it alphabetically.
This would allow your class to work with sorting algorithms that expect a < operator to be defined.


All times are GMT -5. The time now is 04:05 AM.