Structs and linked lists

Can someone please help me understand why pPre->head = NULL is giving me an error. Also why is pLoc = list->head not allowed?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
struct node{
	int data;
	node *backward;
	node *forward;
};

struct list{
	int count;
	node *head;
	node *rear;
};

  bool SearchList(int target)
{
	bool found;
	list *pPre = new list;
	list *pLoc = new list;
	
	pPre->head = NULL;
	pLoc = list->head;
}      
Last edited on
closed account (SECMoG1T)
why pPre->head = NULL is giving me an error
what error did you get?

why is pLoc = list->head not allowed?
because list is a type not an object , you would need to use an object of type list
to accomplish what you want.
Last edited on
It says identifier NULL is undefined.
> It says identifier NULL is undefined.

#include <cstddef>. Or better: pPre->head = nullptr ;
http://en.cppreference.com/w/cpp/types/NULL
Did you include any of the required headers?
I just included all those headers and it still gives me the same error. And it says cannot open source file for all the headers I included
I just included all those headers
You just need to include one.

And it says cannot open source file for all the headers I included
It seems that you compiler broke. What do you use?
I am using GNU GCC.
Are you sure that it is installed properly? Can you build a simple helloworld example?
1
2
#include <iostream>
int main() { std::cout << "Hello, world!\n"; }
I just ran this code and it compiled and ran.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main()
{
   	cout << "hello world" << endl;

    system("pause");
    return 0;
} // end main() 
Topic archived. No new replies allowed.