C++ 调试断言失败_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
C++ Debug Assertion Failed _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
我在这里看过类似的问题,但仍然无法意识到,我做错了什么。请帮助。
我需要制作模板的字符串类与有限的大小(如在Pascal)代码如下:http://pastebin.com/syZf3yM8
错误如下:https://i.stack.imgur.com/4Jo8i.png
在my_string析构函数中,您的代码是:
~my_string () {
delete [] this->text;
}
不应该这样做,因为text是数组,而不是指针。当你调用*S3 = *S1 + *S2
时,my_string <max_size, T> operator+(const my_string& s)
也会被调用。在这个运算中,my_string <max_size, T> res
是一个局部变量,位于堆栈中。此功能结束后,res将被自动删除。所以给S3分配资源是错误的。你可以这样修改:
~my_string () {
}
my_string <max_size, T> operator+(const my_string& s) {
my_string <max_size, T> res;
int count = 0;
while (this->get_char(count) != ' ') {
res.set_char(this->get_char(count), count);
count++;
}
for(int i = 0; count < max_size; i++){
if (s.get_char(i) == ' ') { res.set_char(' ', count); break; }
res.set_char(s.get_char(i), count);
count++;
}
return res;
}
my_string& operator=(const my_string& s){
int size=s.get_length();
for (int i = 0; i < size; i++){
this->set_char(s.get_char(i),i);
}
return *this;
}
最后在主功能中:
delete S1;
delete S2;
delete S3;
相关文章:
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 在函数中删除第一个元素后,如何更新链接列表的phead
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- 错误c++visual studio c2227左侧'->;Init';必须指向类/结构/联合/泛型类型
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- ``这个''不能用this-&gt;指针变量
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 调试断言失败 BLOCK_TYPE_IS_VALID (pHead->nblockuse) 从解构函数
- 使用shared_ptr<字符串>转换为一个无序集合<字符串>