我正在C++中重新創建一個鏈表,並且在重載+ =操作符時出現壞指針。我想我只是以錯誤的方式使用分配器,但我可能是錯的。C++ std :: allocator :: allocate()給我一個不好的指針
這裏是上下文:
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;
}
}
其中first
和current
是Node*
類型。 在此先感謝!
你得到了什麼錯誤? – Brian