Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 5th, 2008, 04:35 PM
Tony Winslow
Guest
 
Posts: n/a
Default Writing an own string class

Hi, there!

Some users of this group mentioned before that
being able to write one's own string class in
C++ is a sign of mastering the basics of the
language. My problem is that I don't quite
understand how does that work. I mean writing a
string class is not very hard, but how can I
determine the string class is working properly
enough or even efficient enough? What is the
benchmark thing that I can use?

Tony Winslow
  #2  
Old July 5th, 2008, 05:35 PM
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
 
Posts: n/a
Default Re: Writing an own string class

On 2008-07-05 17:28, Tony Winslow wrote:
Quote:
Hi, there!
>
Some users of this group mentioned before that
being able to write one's own string class in
C++ is a sign of mastering the basics of the
language. My problem is that I don't quite
understand how does that work. I mean writing a
string class is not very hard, but how can I
determine the string class is working properly
enough or even efficient enough? What is the
benchmark thing that I can use?
The requirements on strings are not universally agreed upon, different
people have different requirements. If you can not come up with the
requirements yourself you can look at some existing implementations
(like std::string, QString, etc.). The same goes for performance, find
an implementation with similar functionality to yours and devise some
benchmarks to compare them, or look up some existing benchmarks.

--
Erik Wikström
  #3  
Old July 5th, 2008, 06:15 PM
osmium
Guest
 
Posts: n/a
Default Re: Writing an own string class

"Tony Winslow" writes:
Quote:
Some users of this group mentioned before that
being able to write one's own string class in
C++ is a sign of mastering the basics of the
language. My problem is that I don't quite
understand how does that work. I mean writing a
string class is not very hard, but how can I
determine the string class is working properly
enough or even efficient enough? What is the
benchmark thing that I can use?
You write your own tests as you go along, starting with the fundamentals and
eventually testing for all the corner cases you can think of. Then release
it to the wild Off the top of my head, and probably with errors something
like this:

Your string class is String. '+' is concatenate. Include a show() function
in as a test device.

String S s("abc");
s.show();
----
String S t();
t.show();
----
modifies x
void f(&S x) { }
....
String S u("abc");
u.show();
----
String S d("abc", e("def");
d = e + d;
d.show();
---
String S a("abc"), b, c;

c = b= a;
____
Something with arrays of strings. Vectors of strings. Prove it is STL
friendly by sorting your strings. And so on.





 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.