When compiling a C++ source file, if you have multiple headers consisting of bracketed and quoted headers, do the bracketed headers have to always be listed first?
I put a quoted header before a bracketed header and this started giving me redefinition compiler errors.
The header file (utilities.h) is:
#ifndef _UTILITIES_H
#define _UTILITIES_H
#include <vector>
double calcNorm(std::vector <double> array); //template?
#endif
The source file (utilities.cpp) is
#include <math.h>
#include <vector>
#include "utilities.h"
double calcNorm(std::vector <double> array) //template?
{
int n;
double norm = 0;
n = array.size();
for (int i = 0; i < n; i++)
{
norm += array[i]*array[i];
}
norm = sqrt(norm);
return norm;
}
Previously, in the source file, I had #include "utilities.h"
above the bracketed headers and I was getting the following compiler error:
g++ -g -Wall -c utilities.cpp
utilities.cpp: In function ‘double calcNorm(std::vector<double>)’:
utilities.cpp:5:8: error: redefinition of ‘double calcNorm(std::vector<double>)’
double calcNorm(std::vector <double> array) //template?
^
utilities.h:3:8: note: ‘double calcNorm(std::vector<double>)’ previously defined here
makefile:12: recipe for target 'utilities.o' failed