I am practicing g++ to compile my code yet the error "malloc was not declared in this scope" keeps emerging at the beginning. The pieces of my code related to this error looks like:
/*------Basic.h--------*/
using namespace std;
/*------A.h------------*/
class A{
private:
double* _data;
public:
A(int N);
}
/*------A.cpp----------*/
A::A(int N){
_data=(double*)malloc(N*sizeof(double));
}
This problem never emerges when I use Microsoft Virtual Stdio. I therefore tried to add a line
#include <stdlib.h>
to Basic.h, and the error disappears. Now I am wondering why this kind of thing happens. Hasn't "namespace std" already include stdlib.h? Thanks a lot.