Quick question about pointers

1
2
3
4
5
6
7
8
9
10
11
12
struct Student 
{ 
 
   string name; // or char name[] with the max number of characters allowed in a name 
   double gpa; 
   double cur_Hours; 
   Student *next;  //pointer to the next student 
};


Student *head; 
head = NULL; 



i have this struct, and the pointer to the struct called head, yet when I compile (in VS) I get error messages, I cant seem to see what is wrong, surely I dont have to create a pointer for an oject of the struct Student?

(learning the basics of linked lists!)


error C4430: missing type specifier - int assumed. Note: C++ does not support default-int




: error C2040: 'head' : 'int' differs in levels of indirection from 'Student *'

Thanks
Last edited on
you didn't show us enough code.

Paste the line of code that's actually giving you that error.

I don't see anything wrong with the above code other than line 12 being global (which would cause an error, but not the one you're describing).
Hi that pretty much is my whole code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include <iostream>
using namespace std;

struct Student 
{ 
 
   string name; // or char name[] with the max number of characters allowed in a name 
   double gpa; 
   double cur_Hours; 
   Student *next;  //pointer to the next student 
};


Student *head; 
head = NULL; 

int main()

{
	return 0;

}



The two errors are on the line head = NULL,


thanks
You can't do that. I *think* you can do this instead though:
Student* head = NULL;

If that doesn't work, you will need to move the head = NULL line into main().

However, globals are evil and I would suggest moving that global into main().
Sorted thankyou, I guess you cant declare a pointer to be NULL globally,
No, it's that you can't have a statement outside of a function. The only things that can go outside functions are expressions and function definitions/declarations, as well as preprocessor macros.
Topic archived. No new replies allowed.