RE: [Dev-C++] Super charging the string class
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-07-04 17:20:20
|
=20 -----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. =20 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 =3D, << = and +=3D operators). =20 What would be the best way to do this? =20 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).=20 =20 std::string is basically a typedef of basic_string<char>. That is , it = is: =20 typedef basic_string<char> string; =20 =20 You can inherit from both, but i assume you intent to inherit basic_string<char>. =20 =20 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. =20 =20 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. =20 =20 To see the basic_string members you can check the stanndard, TC++PL 3, = or the web. =20 =20 =20 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.=20 =20 =20 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! =20 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). =20 TC++PL tells about this somewhere (as it does for comment style using // = for comments and /* */ only for debugging). =20 I summary the master in TC++PL talks about everything! :-) =20 =20 =20 =20 =20 =20 Ioannis Vranos * Programming pages: <http://www.noicys.freeurl.com/> http://www.noicys.freeurl.com * Alternative URL 1: <http://run.to/noicys> http://run.to/noicys * Alternative URL 2: <http://www.noicys.cjb.net/> = http://www.noicys.cjb.net =20 |