My Eclipse program dosn't recognize `NULL` [duplicate] - c++

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
error: ‘NULL’ was not declared in this scope
i'm having this code, which has been written in visual studio but i`m working in eclipse and i'm trying to make it compilable for eclipse and i throws me this error
..\heap.cpp:104:10: error: 'NULL' was not declared in this scope
code:
#include"heap.h"
using namespace std;
template<class T>
Heap<T>::Heap() // constructor
{
root = NULL;
size = 0;
}

Eclipse isn't a compiler, just an IDE. I'm guessing you're using it with another compiler than Visual Studio and the system headers are somewhat different, leading to your VC++ working includes to not include the declaration of NULL on <the other compiler>. As Martinho Fernandes said, you need to include <stdlib.h> or <cstdlib>, or some header that includes those ones. As the other question says, the C++ 11 way would be <stddef.h> or <cstddef>.

Related

VS2017 'M_PI': undeclared identifier [duplicate]

This question already has answers here:
M_PI works with math.h but not with cmath in Visual Studio
(7 answers)
Closed 4 years ago.
I'm trying to compile a library in C++ as dll windows with visual studio 2017.
I have all C++/H compiled with clang 3.8 for android and it works.
I created a new project as dynamic library with LLVM as platform toolset. Now I'm trying to build but there is an error :
Error C2065 'M_PI': undeclared identifier
This error is present in many .cpp files. All linked .h contains :
#include <cmath>
I replaced by :
#define _USE_MATH_DEFINES // for C++
#include <cmath>
But it change nothing. What can I do ?
This is a known issue, try defining _USE_MATH_DEFINES as a definition in your project properties instead of the file itself.
This can be found in project properties -> C/C++ -> Preprocessor -> Preprocessor definitions.

iostream.h: no such file or directory [duplicate]

This question already has answers here:
fatal error: iostream.h no such file or directory [duplicate]
(3 answers)
Closed 6 years ago.
I am using Windows 8.1 and Dev C++ and I have the following code:
#include<iostream.h>
main()
{
cout<<"welcome to devc++";
system("pause");
}
The syntax is correct, but I get an error that says:
[Error] iostream.h: No such file or directory
I have tried to change to location of this .cpp folder, watched video tutorials, but I could not point out why I am getting this error and how to remove it.
You need to use #include<iostream> instead of #include<iostream.h>. The later one has been deprecated now; which is why you face the error. More details here.
Besides, main() being a function, should have a return type. So, you should write int main() and not just main().
Just do,
#include <iostream>
instead of
#include <iostream.h>
because, as C++ progressed from specific implementation to standard one,.h were deprecated from he library.
In addition to changing to
#include <iostream>
You can also add
using namespace std;
before main if you want to use cout without having to use std::cout.

QT Creator does not recognize STL types for new projects [duplicate]

This question already has answers here:
Using std Namespace
(16 answers)
Closed 7 years ago.
I have an existing project where the STL types are recognized. However, when creating a new project none of the STL types are not recognized. For example in
#include <string>
string s;
the colour of stringwill not change and compilation will generate errors.
Strangly enough when on the include line "Follow symbol under cursor" is executed the include file is opened. So the include file is there, Qt Creator knows how to open it and still class string is not recognized.
Did a reinstall of Qt5.5 but no avail.
What's happening?
you should use:
std::string
or:
using namespace std
at the beggining and you will not have to add the namespace every time

Getting Random.h (uses unistd.h) to work on VC++ [duplicate]

This question already has answers here:
Is there a replacement for unistd.h for Windows (Visual C)?
(10 answers)
Closed 9 years ago.
I'm new to C++. I want to use the header file Random.h (described here http://ftp.arl.mil/random/). It uses unistd.h
Which gives me an error
"Cannot open include file: 'unistd.h': No such file or directory"
I've googled around and seen that the issue is that unistd.h works with unix not visual express. Some posts suggest using mingw instead but I've tried that and it doesn't work. Can anyone tell me how to get unistd.h (or at least the bits of it I need) to work on Visual Express.
There are some suggestions online but I cant find anything that addresses my particular question.
thanks!
It is including unistd.h for calls to getpid(). Change the #include to <process.h> and change all the getpid() calls to _getpid() (note the extra underscore at the front).
msdn.microsoft.com/en-us/library/t2y34y40.aspx
Visual C++ will not let you assign static const doubles in the header file (ony integer types). You will need to change the line in the .h file to this...
static const double _F;
Then create a Random.cpp file that just contains this...
#include "Random.h"
// Initialize static variable
const double Random::_F = 1. / Random::_M;

NOMINMAX with Visual Studio 2012 MFC project [duplicate]

This question already has answers here:
Possible problems with NOMINMAX on Visual C++
(4 answers)
Closed 7 years ago.
I want to use #define NOMINMAX in my Visual Studio C++ project using MFC, so that I can use std::min and std::max. However, when I put this line in my stdafx.h, I get following compile error:
c:\program files (x86)\windows kits\8.0\include\um\GdiplusTypes.h(475): error C3861: 'min': identifier not found
I am not using GDI+ intentionally, this is something MFC must be doing. Can the issue be fixed somehow, either by removing the GDI+, or by adjusting it to compile?
I don't work on Windows so I'm not used to dealing with this, and I'm not testing this, but I believe that answer is suggesting you do this:
#define NOMINMAX
#include <algorithm>
namespace Gdiplus
{
using std::min;
using std::max;
};
//... your other includes.
This will get the "proper" versions of min and max, and make them available without the std:: prefix (which seems to be how it is used in the GdiplusTypes.h header).
The winapi min and max are macros, so you can just #undef them after including the MFC or winapi headers:
#undef min
#undef max