c++ - Is it allowed to inherit from a class in the std namespace (namely std::wstring)? -


class std :: wstring "normal" c Some actions are missing for string (and literals).

I would like to add these missing campaigns to my own custom category:

  #include & lt; String & gt; Category CustomWString: public std :: wstring {public: CustomWString (const char *); Const char * c_str (zero); };  

The above code is ok with G ++ v4.4.1 on Ubuntu Karmic.

But am I thinking that there are arguments against doing so?

Edit: To illustrate some examples, what do I mean with the "missing campaign":

  std :: wstring Foo ("hello"); // need something like an L () macro or that string :: string bar ("hello"); Std :: wstring goose (bar.c_str ()); Foo = "hello"; // requires the l () macro foo = bar.c_str (); Foo = bar;  

Edit: I would like to "centralize" somehow That's because I have a project transmitted from M & T - with thousands of these unsuccessful operations.

The best part is: A central place where the type is defined to use the string, for example:

  #ifdef WINDOWS_OS typedef std :: Wstring AppStringClass; #else typedef std :: string AppStringClass; #Adif  

The compiler certainly gives you, because to seal a class There is no way in C ++ with a public manufacturer.

STL containers have not been prepared for legacy , so this is usually a bad idea. C ++ needs to ignore many weird corners. Your derivative class may break with other STL implementations, or just with the update of Build environment.

However, I consider it a string warning signal, not the total number. Is this a "Are you really sure what you are doing, do you know all the implications, and have good arguments against all the options?"

In your case: It is ok to provide additional controllers (because the public interface is documented and you can repeat it), and unless you present the new data members Or VMT, slicing or non-virtual district is not a problem. (Remember to behave in the C ++ Standard Dove unexpected behavior while deleting the base class pointers without the virtual DTER)

However I'm not sure how you want to implement four const * c_str () without providing storage for string. And as soon as you present new data members, you are entering an area in the grounds.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -