I have a number of functions I would like to reuse in multiple pieces of code.
I have put these into a single header file that looks something like the following:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
//function prototypes
extern float sum(vector<float> &v);
//calculate sum of a vector
float sum(vector<float> &v)
{
int num=v.size();
float sum=0.;
for(int ss=0;ss<num;ss++)
{
sum+=v[ss];
}
return sum;
}
#endif
I have included this in more than one file using a line like
#include "functions.h"
When I do this, I get multiple definition errors. I think I have done everything correctly with extern and ifndef, can anybody explain what I am missing?