I know extending built-in classes in C++ is deprecated, but still I want to do it for some reasons.
I wanna add my custom methods to a class (str
) that extends/inherits from the std::string
class (this is for an example)
But when I do so there's some problem I am facing with the methods that are already there in the std::string
class (built-in methods), for example,
#include <bits/stdc++.h>
using namespace std;
class str : public string {
public:
string s;
str(string s1) {
s = s1; //ig the problem is here
}
};
int main() {
str s("hello world");
cout << s.size(); //prints out 0 not 11 => length of "hello world"
}
How do I get around this?