For the fun of it I decided to experiment with some versatile linked list, or whatever it's called, but things don't work quite as expected. My guess is that there's something I've forgotten or simply don't have a proper understanding of.
Code: Select all
#include <vector>
struct Data {
// Data
};
class Node {
public:
std::vector<Node*> next, prev;
Data data;
Node() {}
Node(Node* ptr) {
prev.push_back(ptr);
}
~Node() {
for(int i = next.size() - 1; i >= 0; i--) {
delete next[i];
}
for(int i = prev.size() - 1; i >= 0; i--) {
delete prev[i];
}
}
void NewNode() {
next.push_back(new Node(this));
}
};
int main() {
Node test;
test.NewNode(); // This makes things act up.
}
I do hope you can point out my bummer because I've tried everything I could think about.
Best regards.
Edit:
Problem solved by removing the destructor.
I'm not quite sure why as I've learned that manually allocated memory must also be manually freed.