简体   繁体   English

C ++调试断言失败

[英]c++ debug assertion failed

I have a problem when I try to run this code 我尝试运行此代码时遇到问题

void MyClass::setUp(){
    list->clear();
    Iterator i = ctr.getAll().iterator();
    while (i.valid()) {
        list->addItem(QString::fromStdString(i.elem().getNr()));
        i.next();
    }
}

When I exit the function an error occurs: 当我退出函数时,会发生错误:

Debug Assertion Failed! 调试断言失败!

File:C:\\Program Files \\Microsoft Visual Studio 14.0\\ VC\\ include\\ xmemory0 line:106 文件:C:\\ Program Files \\ Microsoft Visual Studio 14.0 \\ VC \\ include \\ xmemory0行:106

Expression: "(_Ptr_user&(_BIG_ALLOCATION_ALIGNMENT -1))==0 " &&0 表达式:“(_Ptr_user&(_ BIG_ALLOCATION_ALIGNMENT -1))== 0” && 0

I am trying to iterate through a custom list 我正在尝试遍历自定义列表

The Iterator class is this: Iterator类是这样的:

void Iterator::first(){
    while (pos < ht.nrElem && ht.list[pos] == nullptr)
        pos++;
    if (pos < ht.nrElem)
        current = ht.list[pos];
}

Iterator::Iterator(const HashTable & ht): ht { ht }{
    pos = 0;
    first(); // current will refer the first element of the list
}


void Iterator::next(){
    current = current->getNext();
    if (current == nullptr) {
        pos++;
        first();
    }
}

bool Iterator::valid(){
    return (pos < ht.nrElem) && (current != nullptr);
}

Car& Iterator::elem() const{
    return current->getCar();
}

For one thing, Iterator::first and thus the constructor do not neccessarily initialize current . 一方面, Iterator::first ,因此构造函数不必初始化current Second, in Iterator::Iterator(const HashTable & ht): ht { ht } does it mean that Iterator has a member ht , and the parameter is also called ht ? 其次,在Iterator::Iterator(const HashTable & ht): ht { ht }是否表示Iterator具有成员ht ,并且该参数也称为ht It is a bad practice. 这是一个坏习惯。 Never call parameters of member functions the same name as class fields. 永远不要调用与类字段同名的成员函数参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM