C
Carl Youngblood
I imagine this subject has probably been brought up numerous times.
Forgive me for bringing it up again. I was googling through old posts
on this newsgroup about it and found a good suggestion on how to add
functionality to the string class. Rather than trying to inherit from
the string class, the author was suggesting wrapping the string class
in another class, like so:
The only confusing thing about his post was that he said this at the
end:
I don't know exactly what he meant by "Don't forget to define the
value type, iterator type and reference type". I've done a good bit
of C++ programming but am by no means an expert.
Thanks for your help,
Carl Youngblood
Forgive me for bringing it up again. I was googling through old posts
on this newsgroup about it and found a good suggestion on how to add
functionality to the string class. Rather than trying to inherit from
the string class, the author was suggesting wrapping the string class
in another class, like so:
Right !!!, we should not derive from string, but we should wrap the
string class, for example.
class Mystring {
string data;
Mystring(char* x) : data(x){};
Mystring(string* x) : data(x){};
Mystring& operator=(const Mystring& x){
data=x.data;
return *this.
}
}
The only confusing thing about his post was that he said this at the
end:
This is actually a very easy thing to do. You just have to check all the
interface functions of string class (which is basic_string<char>) and do the
same inline like above. The new class will have about the same efficiency as
the std::string class one (because of the inlining), however, you will be
able to extend your own additions of behaviors. Don't forget to define the
value type, iterator type and reference type, like this ....
typename string::value_type value_type;
and etc .....
I don't know exactly what he meant by "Don't forget to define the
value type, iterator type and reference type". I've done a good bit
of C++ programming but am by no means an expert.
Thanks for your help,
Carl Youngblood