Hey everyone so my professor wants us to use Malloc in order to allocate memory for a linked list for our project. When I did this I got an error of: C2027 use of undefined type 'Node' and I can't figure out what is wrong. Yes I would love to use 'new' but our professor strictly said we cannot use it. My code isn't anything impressive because I just started out but this is what I got:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
struct Node * node = (struct Node*)malloc(sizeof(struct Node));
free(node);
return 0;
}
struct Node
{
char* _curr;
int _line;
Node *next;
}
|
I have tried a combination of:
struct Node * node = (struct Node*)malloc(sizeof(struct Node));
struct Node * node = (Node*)malloc(sizeof(struct Node));
Node * node = (struct Node*)malloc(sizeof(struct Node));
Node * node = (Node*)malloc(sizeof(struct Node));
Node * node = (struct Node*)malloc(sizeof(Node));
The only one that actually works is this one:
struct Node * node = (struct Node*)malloc(sizeof(struct Node*));
but when I added new nodes and quit my program I got a HEAP CORRUPTION DETECTED while trying to use the free(node);
so yeah I am pretty stumped any help would be appreciated and thanks in advance