J
Jim Kogler
I have created a new string type with a memory pool allocator. Lets
presume the allocator works, my type is defined as:
typedef std::basic_string<char, std::char_traits<char>,
pool_allocator<char> > NewStr;
This is the same as std::string except with a different allocator,
right?
I want to be able to implicitly convert from std::string to NewStr
like:
std::string a("hi");
NewStr b("there");
a = b;
or
b = a;
which doesnt work, becasue they are different types. So my question
is, if i wanted to do this:
class MyString : public NewStr
{ public:
MyString &operator=(const std::string &other)
{
// what is the best way to do this?
*this = other.c_str(); /// doesnt look good...
return *this;
}
of course the same question could apply to the copyCtor too...
and, to go the other way, should i do the same thing for the
operator const std::string&() {...} method?
Is there a better way to create my type?
Jim
presume the allocator works, my type is defined as:
typedef std::basic_string<char, std::char_traits<char>,
pool_allocator<char> > NewStr;
This is the same as std::string except with a different allocator,
right?
I want to be able to implicitly convert from std::string to NewStr
like:
std::string a("hi");
NewStr b("there");
a = b;
or
b = a;
which doesnt work, becasue they are different types. So my question
is, if i wanted to do this:
class MyString : public NewStr
{ public:
MyString &operator=(const std::string &other)
{
// what is the best way to do this?
*this = other.c_str(); /// doesnt look good...
return *this;
}
of course the same question could apply to the copyCtor too...
and, to go the other way, should i do the same thing for the
operator const std::string&() {...} method?
Is there a better way to create my type?
Jim