0

这是对的?

class SearchString : public NString {

  DataForSearchInString dataForSearchInString;

public:
    SearchString():NString(){}
    SearchString(const char * data):NString(data){}
    SearchString(const SearchString & other) : NString(other), dataForSearchInString() {}

    SearchString& operator=(const SearchString& other)
    {
        NString::operator=(other);
        dataForSearchInString.setBegin(other.getBegin());
        return *this;
    }

    // if will be classes - children or there any virtual function then need to write "virtual ~SearchString() {}"  here 

    //  Some functions 
    inline const int getBegin() const {return dataForSearchInString.getBegin();} 
};
4

1 回答 1

0

看起来不错,但我想你忘记了DataForSearchInString(other.dataForSearchInString)

class SearchString : public NString {

    DataForSearchInString dataForSearchInString;

public:
    SearchString():NString(){}
    SearchString(const char * data):NString(data){}
    SearchString(const SearchString & other) : 
                            NString(other),
                            DataForSearchInString(other.dataForSearchInString) {}
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    SearchString& operator=(const SearchString& other)
    {
        NString::operator=(other);
        dataForSearchInString.setBegin(other.getBegin());
        return *this;
    }
};
于 2013-05-01T21:41:25.310 回答