这是对的吗?
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();}
};
答案 0 :(得分: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;
}
};