'NULL' undeclared...
Denis Sinner

I Wrote a class which includes an pointer to the next Object of the same class. It worked fine. Then i tried to place the class in it's own header h. + .cpp file. Now when i'm trying to compile, i'm getting the following error:(I'm Using Dev cpp)

`NULL' undeclared (first use this function)

(I'm using NULL in the constructor for the pointer to the next Object)

Chris Katko

Include a standard header perhaps?

Korval

I would venture the following guess. One of the .cpp files that includes the .h file includes it before including anything else (like <stdlib.h> and so forth). You should include your standard library headers first.

Radagar

I know this makes a difference with Visual Studio, but I'm not sure about DevCpp.

Try renaming the .h file to .hpp

NULL is not declared in C, but is in C++, if I remember correctly.

Zaphos

You could just do:

#ifndef NULL
#define NULL 0
#endif

Radagar: NULL is declared in standard header files. I'm not sure why .h -> .hpp would do anything at all ... it sounds silly.

Billybob

I'm wondering why no one ranted yet... [url http://www.allegro.cc/forums/view_thread.php?_id=331783]

23yrold3yrold

Yeah, I was about to link that :)
Almost certianly, that's his problem.

Chris Katko
Quote:

Radagar: NULL is declared in standard header files. I'm not sure why .h -> .hpp would do anything at all ... it sounds silly.

He didn't include any standard header files first off, secondly there's a difference between c and cpp files.

And ofcourse, read the link.

Zaphos
Quote:

He didn't include any standard header files first off, secondly there's a difference between c and cpp files.

I know both these things, I've read the link (before reading this thread, actually), and your post has no relevance whatsoever to what you quoted.

Chris Katko

The "And ofcourse, read the link." part was for the OP.

Surt

NULL is declared in <stddef.h> under C and <cstddef> under C++.

Thread #332697. Printed from Allegro.cc