【发布时间】:2016-04-26 11:59:43
【问题描述】:
//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 数据成员不会被保留。
//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;
}
【问题讨论】:
-
欢迎来到 Stack Overflow!请将您的问题editminimal reproducible example 或SSCCE (Short, Self Contained, Correct Example)
-
告诉我们
MyString的定义 -
你做关注the rules of three, five or zero参加
MyString课程?您是否有理由不使用标准的std::string类? -
@JhennaForonda 请不要将代码或其他重要且重要的信息作为 cmets 发布,请编辑您的问题以包含它。
-
在那个复制构造函数中,你在哪里初始化
i?mLength是否包含字符串终止符?