Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;std::allocator::allocate()给了我一个错误的指针 < >我正在重新创建C++中的链表,并且在重载+=运算符时得到一个坏指针。我想我只是以错误的方式使用了分配器,但我可能是错的_C++_Pointers - Fatal编程技术网

C++;std::allocator::allocate()给了我一个错误的指针 < >我正在重新创建C++中的链表,并且在重载+=运算符时得到一个坏指针。我想我只是以错误的方式使用了分配器,但我可能是错的

C++;std::allocator::allocate()给了我一个错误的指针 < >我正在重新创建C++中的链表,并且在重载+=运算符时得到一个坏指针。我想我只是以错误的方式使用了分配器,但我可能是错的,c++,pointers,C++,Pointers,以下是上下文: void MyLinkedList::operator+=( const std::string& s ) { allocator<Node> a; Node* n = a.allocate(1); Node node(s); (*n) = node; if ( first == NULL ) first = n; else { (*current).SetNext(n)

以下是上下文:

void MyLinkedList::operator+=( const std::string& s )
{
    allocator<Node> a;
    Node* n = a.allocate(1);

    Node node(s);
    (*n) = node;
    if ( first == NULL )
        first = n;
    else
    {
        (*current).SetNext(n);
        current = n;
    }
}
void MyLinkedList::operator+=(常量std::string&s)
{
分配器a;
节点*n=a.allocate(1);
节点;
(*n)=节点;
if(first==NULL)
第一个=n;
其他的
{
(*当前).SetNext(n);
电流=n;
}
}
其中
第一个
当前
属于
节点类型*
。 提前谢谢

分配未构建的原始存储。要使用存储,必须使用
.construct()


你犯了什么错误?谢谢!现在,在设置
节点中
当前所指向的
节点的
节点*下一个
的旧指针时遇到问题。它告诉我在那个书写位置有一个访问冲突。我在谷歌上搜索了一下,似乎我可能在只读内存中创建了我的
节点。我有没有,如果有,我该如何把它放在可写内存中?
a.construct(n, /* initializer */);