jeudi 30 juin 2016

What should I override in inheritance when it comes to light derivation?


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.

  1. 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.

  2. 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 not virtual?

  3. Is the code in operator() legal base on my functionality set in public:? The compiler doesn't tell me any thing. But I'm quite skeptical.


Aucun commentaire:

Enregistrer un commentaire