Re: [Dev-C++] Super charging the string class
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2003-07-04 18:33:46
|
MessageI see. So sub-classing basic_string<char> would be the reccomended way to do this then?
With respect to the over-ridden methods I am wondering whether you have some example code that I can see. I know how to call base class methods from a derived class but what I need is a way to reverse the default method called (usually the derived method is called, I want the base to be called, if one exist)
----- Original Message -----
From: Ioannis Vranos
To: 'Dev-Cpp Mailing List'
Sent: Friday, July 04, 2003 1:19 PM
Subject: RE: [Dev-C++] Super charging the string class
-----Original Message-----
From: dev...@li... [mailto:dev...@li...] On Behalf Of David McKen
Sent: Friday, July 04, 2003 7:51 PM
To: Dev-Cpp Mailing List
Subject: [Dev-C++] Super charging the string class
I am currently writing a heavy text-processing application.
As far as I can see the string class is not implemented uniformly. I wish to fill in the gaps as well as add a few extras that are used on a regular basis in the program (not the least of which are overloading the =, << and += operators).
What would be the best way to do this?
I was thinking create a class that inhereted from the string class and make my changes to that class. The only thing I am a bit curious about with this method is what happens if I override a function that exist on one of the platforms. How can I check for it's existence at compile time (Odds are the compiler writer's implementation is faster or more stable than mine).
std::string is basically a typedef of basic_string<char>. That is , it is:
typedef basic_string<char> string;
You can inherit from both, but i assume you intent to inherit basic_string<char>.
If you override an already existing function it will happen as always. Your inherited class member function will be executed for your inherited class instances (objects). As always however if you use a base pointer (pointer to std::string) the string member function will be executed.
Another way is to have an std::string object as a data member in your new type but in this case you would have to provide the whole string interface.
To see the basic_string members you can check the stanndard, TC++PL 3, or the web.
Another thing I saw and would like an opinion on is making all my overloads global. (i.e. instead of being part of the class they are normal functions thet implement the overloads). I see this getting a bit unweildly though.
In any case you should place your new string type inside a namespace. In this way you can even use the name string for your class!
As a general rule of style, definitions of operators having to do with objects of the same class are placed inside the class, and operators having to do with objects of other types are placed as "global" (in the namespace).
TC++PL tells about this somewhere (as it does for comment style using // for comments and /* */ only for debugging).
I summary the master in TC++PL talks about everything! :-)
Ioannis Vranos
* Programming pages: http://www.noicys.freeurlcom
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo. |