PDA

Click to See Complete Forum and Search --> : String class


CornedBee
Jun 6th, 2002, 04:13 PM
I'm working on an extended string class (derived from STL string). What features do you think it should support?

parksie
Jun 6th, 2002, 04:34 PM
I don't think you can derive from it (no virtual destructor).

You'd have to implement it as an adapter.

CornedBee
Jun 6th, 2002, 04:51 PM
hmmmm... true, that's what I don't like about the standard library...

What's an adapter?

parksie
Jun 6th, 2002, 05:51 PM
It's like that for efficiency reasons (similar to a final Java class), and you wouldn't normally want to derive from the standard containers.

An adapter extends or alters the functionality by compositing an object inside another. Take a look at the source to stack<>, I think that internally uses deque<> to handle the allocation.

CornedBee
Jun 7th, 2002, 02:41 AM
I see.
But since my own destructor does nothing (~WString(){}), does it matter?
WString& destructed -> ~WString() called -> ~tstring called
tstring& destructed -> ~tstring called

Since ~WString does nothing, do I loose anything? Or does the destructor do some secret things I don't know about?

Oh, tstring is defined like this:
#ifdef UNICODE
typedef wchar_t tchar_t;
#else
typedef char tchar_t;
#endif
typedef basic_string<tchar_t> tstring;



I think final Java classes exist mainly for security reasons - so that no one can derive a class and manipulate behaviour.

parksie
Jun 7th, 2002, 09:52 AM
Whether a particular implementation does anything "secret" in its destructor is up to the implementer, and you can't rely on it.

I don't know completely what the standard says about the string class, but I definitely know you can't derive from the standard containers.

What sort of functionality were you thinking of adding?

CornedBee
Jun 7th, 2002, 10:45 AM
Functions that do nice things. Search, Strip, Trim, all those things. Maybe RegExp capability.

parksie
Jun 7th, 2002, 10:57 AM
Well, it's already got find, but trim is a good one to have.

For regexps, see those boost classes :D www.boost.org