   String Wrappers
  I''m doing my own string class to get myself familiarised with operator overloading.I''ve seen other string classes that allow you to do:String   MyName="John Doe";Messagebox(MyName);My class has a char* array which I resize as needed, and to use my class i have to doMessagebox(MyName2.charArray);...where ".charArray" is my char*....So how do i remove the whole ".charArray" part, so that it auto-returns the string by name alone, like so:Messagebox(MyName2);Also, what is the correct string format to use under win32, zero-terminated char strings are good enough?Thanks for any tips on this...   [Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]    [Yann  L.][Enginuity]  [Penny Arcade]  [MSDN][VS  RoadMap][Humus][BSPs][UGP][NeHe]"I say we take off and nuke the entire site from orbit. It''s the only way to be sure." 
  overload the char* operator.. although you should really be overloading the const char* operator   "That''s not a bug, it''s a feature!"  --me ;  One simple method within a string class is to use a vector of chars under the private label. Honestly, I don't understand why you need to call a member function to get at the data. You can define insertion << or extraction >> overloaded operators to use data from the array or vector of chars. When you pass an object of the class, through assignment/initialization as a function parameter your constructors should be doing the dirty work. Have one copy constructor take a const char* parameter, and another a size_type, and char. The compiler should use implicit conversions where necessary. I could post a string class I have, but you might not want that much help. It might be best though, if you want more specific help that you paste your class and associated functions so folks can throw in their wisdom.   [edited by - nervo on February 3, 2004 1:21:39 AM];  inline operator const char* () const{   return data;}where data is the pointer to your array. ;  class String {  operator const char*()  {    return Len() ? Data : _T("");  }  DWORD Len() const  {    return Data ? _tsclen(Data) : 0;  }private:  char *Data;} ;  You think you want to do this, but you don''t. It triggers an implicit conversion to const char* which is very difficult to track down. ;quote:Original post by antareus  You think you want to do this, but you don''t. It triggers an implicit conversion to const char* which is very difficult to track down.Listen to this man. ;  There is a good reason why std::string provides the explicitc_str() and no implicit conversion to const char *.Google it.   Kami no Itte ga ore ni zettai naru! ;  well, my string class has a char* which starts out as null, and gets asigned/resized as operations are performed onto it...i also provide some stuff like:int = mystring;mystring = int;mystring = char*;...is that bad design?btw, why cant i do this:mystring = "1"+"2"+"3";I allways get a "cannot add two pointers" on that one...   [Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]    [Yann  L.][Enginuity]  [Penny Arcade]  [MSDN][VS  RoadMap][Humus][BSPs][UGP][NeHe]"I say we take off and nuke the entire site from orbit. It''s the only way to be sure." ;quote:Original post by pentium3id  well, my string class has a char* which starts out as null, and gets asigned/resized as operations are performed onto it...That''s not the problem. The problem is with implicit conversions, because of ambiguous situations that cause very hard-to-track-down bugs. Like tangentz said, Google the rationalizations for std::string::c_str.quote:i also provide some stuff like:int = mystring;mystring = int;mystring = char*;...is that bad design?Well, not really. It does raise the question what happens when you assign a non-numeric string to an integer variable, or when the numeric characters in a string are in the middle.quote:btw, why cant i do this:mystring = "1"+"2"+"3";I allways get a "cannot add two pointers" on that one...Because a string is not a first class type in C++; a char * is. Also check the operator precedence: the addition is completed first. 