Basically, I have a large project that uses a custom utility class c_string that inherits from std::basic_string<char>. For numerous reasons, I would like to edit this class so that
- It does not derive from
std::basic_string<char> - I do not have to re-implement all the functions
- I do not have to touch every file that uses
c_string
So I want to change from:
class c_string : public std::basic_string<char>
{
public:
typedef std::basic_string<char> Base;
c_string() : Base() {}
}
To:
class c_string
{
...
public:
...
c_string() {...}
}
So, I’m wondering if anyone has a good strategy for making this change with minimal impact.
If your class adds custom functionality (that your project needs) over
std::string, then you’re out of luck: you will either have to encapsulatestd::string(and implement all methods to forward tostd::stringimplementation) or inherit fromstd::string(inheriting fromstd::stringis not a good idea in general).If your class doesn’t add extra functionality over
std::string, then replaceclass c_string { ... }withtypedef std::string c_string;.