Is it Dangerous to Derive from STD? Specifically std::string.
Why I'm asking?
I want to write a class that extends the functionality of std::string and a couple other std structs/classes.. So that when I do something like:
String M = "";
M.Explode(........) it'll do the functionality in my class below.
Thing is I'm reading that it's very dangerous (on google at least).. and that I should "NEVER DERIVE FROM STD!!!!" because something about the destructor or constructor being virtual sometimes?
For example:
class Strings : public std::string
{
private:
vector<string> &SplitWrapper(const string &s, char delim, vector<string> &elems)
{
stringstream ss(s);
string item;
while(getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}
public:
vector<string> Explode(const string &s, char delim)
{
vector<string> elems;
return SplitWrapper(s, delim, elems);
}
string Implode(string Glue, string Pieces[])
{
int I, Len;
string Result = "";
Len = HIGH(Pieces);
if (Len < 0)
return Result;
Result = Pieces[0];
for (I = 1; I < Len; I++)
Result += Glue + Pieces[I];
}
string Implode(const string &Glue, const vector<string> &Pieces)
{
string Str;
int Len = Pieces.size();
for(int I = 0; I < Len; I++)
{
Str += Pieces[I];
if (I < (Len - 1))
Str += Glue;
}
return Str;
}
bool isUpper()
{
}
};