//prototype
void Split(char c, vector <MyString> &outputVector) const
//partial code inside split function
// create new MyString object to push into output vector
MyString substr;
substr.mString = newString;
substr.mLength = size;
// push new item
outputVector.push_back(substr);
当我跨过outputVector.push_back()
行后,mString
数据成员不会保留。push_back结构化为向量
//I have two constructors
MyString()
{
mString = NULL;
mLength = 0;
}
/*************************************************
* MyList copy constructor
* creates a deep copy of a MyString item
************************************************/
MyString(const MyString ©)
{
mString = new char[copy.mLength];
int i;
for(; i < copy.mLength; i++)
{ mString[i] = copy.mString[i]; }
mString[i] = '\0';
mLength = copy.mLength;
}
欢迎来到堆栈溢出!请** [编辑] **您的问题用[mcve]或[SSCCE(Short,Self Contained,Correct Example)](http://sscce.org) – NathanOliver
向我们展示'MyString'的定义 –
You * do *遵循[MyString'类的[三,五或零规则](http://en.cppreference.com/w/cpp/language/rule_of_three))?有没有原因你不使用标准的'std :: string'类? –