LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2005, 11:03 AM   #1
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
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
 
Old 08-23-2005, 12:06 PM   #2
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a c++ binary safe string class? Thinking Programming 3 08-11-2005 06:18 PM
questions about custom compile byte.chaser Debian 36 07-14-2005 06:51 PM
Linking problem with string class live_dont_exist Programming 4 04-09-2005 08:07 AM
std string class and printf The_Nerd Programming 3 06-28-2004 10:46 PM
Problem for RedHat 7.1 Custom-Class Partition ShiN Linux - Newbie 1 01-13-2003 05:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration