How can I prevent the duplication of stdlib.h in main.cpp?
Code:
// AllocateVector.h
#ifndef ALLOCATEVECTOR_H
#define ALLOCATEVECTOR_H
#include <stdlib.h>
template <class dataType>
int allocateData1DbyMalloc(dataType*& data1D, unsigned int nRow) {
data1D = (dataType*)malloc(nRow * sizeof(dataType)); // sizeof(type1));
return (data1D != NULL) ? EXIT_SUCCESS : EXIT_FAILURE;
}
#endif
// AllocateMatrix.h
#ifndef ALLOCATEMATRIX_H
#define ALLOCATEMATRIX_H
#include <stdlib.h>
int allocateData2DbyMalloc(dataType**& data2D, unsigned int nRow, unsigned int nColumn) {
data2D = (dataType * *)malloc(nRow * sizeof(dataType*)); // calloc(nRow, sizeof(type1*));
if (data2D == NULL) {
return EXIT_FAILURE;
}
// Now point each row to an array of nColumn type1 objects
for (unsigned int i = 0; i < nColumn; ++i) {
data2D[i] = (dataType*)malloc(nColumn * sizeof(dataType)); //calloc(nColumn, sizeof(type1));
if (data2D[i] == NULL) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
#endif
//main.cpp
#include "AllocateVector.h"
#include "AllocateMatrix.h"
int main()
{
return 0;
}