class MyString :public string {
public:
using string :: string;
using string :: operator=;
bool operator== (MyString&);
bool operator< (MyString&);
bool operator> (MyString&);
MyString& operator= (MyString&);
MyString& operator= (string&);
MyString operator() (int, int);
friend ostream & operator<<(ostream&, MyString&);
};
MyString MyString::operator() (int a, int b) {
MyString os;
os = string::substr(a, b);
return os;
}
Note: I'm using cstring
It's my learning experiment. I am confused when it comes to light derivation like code above.
Suppose I just want to add feature that can get substring by (int, int) operator, but I realize I can't use those functions that take
MyString
parameters.I have tried to use using for those operators
==
,<
,>
but that doesn't work. The compiler tells me that string don't have those operator, I wonder it's because those functions in string are notvirtual
?Is the code in
operator()
legal base on my functionality set inpublic:
? The compiler doesn't tell me any thing. But I'm quite skeptical.
Aucun commentaire:
Enregistrer un commentaire