<stddef.h> std::ptrdiff_t' has not been declared

3k Views Asked by At

I have made my own source file, and I'm trying to add stddef.h. At compiling I have the following error:

std::ptrdiff_t' has not been declared.

What I've done wrong?

1

There are 1 best solutions below

3
On BEST ANSWER

The problem is that you are including the standard C header, not the standard C++ header.

The standard C header will not put their symbols in the std namespace, since C doesn't have such things.

That you have other applications requiring the C header doesn't matter, if you want to use the ptrdiff_t type-alias from the C++ std namespace, you must include <cstddef>.

Or stop using std::ptrdiff_t and user the unqualified and global ptrdiff_t from <stddef.h>.