#include trouble

Hello Everybody,

I have a problem while #including .h files.

My Project is as follows. I picked up the files randomc.h and sfmt.h from www.agner.org/random.

I wrote a Normal.h using Numerical Recipes in Finance.

In sfmt.cpp I added this line:

1
2
#include "C:\Users\Jason\Documents\Visual Studio 2010\Projects\ExcelConnection\ExcelConnection\sfmt.h"


the Normal.h looks like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdlib>
#include <cmath>
#include "C:\Users\Jason\Documents\Visual Studio 2010\Projects\ExcelConnection\ExcelConnection\randomc.h"

using namespace std;

CRandomSFMT Uniform(1);

double Normal(void){
	
	double U1, U2, V1, V2;
	double S=2;
	while(S>=1){
		U1=Uniform.Random();
		U2=Uniform.Random();
		V1=2.0*U1-1.0;
		V2=2.0*U2-1.0;
		S=pow(V1,2)+pow(V2,2);
	};
	double X1=V1*sqrt((-2.0*log(S))/S);
	return X1;
};



and now i'm trying to run this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17


#include <cmath>
#include <iostream>

#include "C:\Users\Jason\Documents\Visual Studio 2010\Projects\ExcelConnection\ExcelConnection\sfmt.h"
#include "C:\Users\Jason\Documents\Visual Studio 2010\Projects\ExcelConnection\ExcelConnection\randomc.h"
#include "C:\Users\Jason\Documents\Visual Studio 2010\Projects\ExcelConnection\ExcelConnection\Normal.h"

using namespace std;

int main(){


	system("PAUSE");
	return 0;
}


Problem: this is not building, I got errors. Could you help me understand why?

thank ou so much!!
check that in all your header files, you dont have circular #includes .

http://stackoverflow.com/questions/3127171/how-are-circular-includes-resolved
Thanks for the reply.

yes i should have guarded the #includes with #ifndef statement.

However I wonder if it's a clean way to use a function defined in a header file? I mean Just #including the .h path of my function Normal.

Thank you again!!
yes i should have guarded the #includes with #ifndef statement.
That is not how it works.

Guards benong to the header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*header.h:*/
#ifndef HEADER_H
#define HEADER_H

//Header content

#endif

/*main.cpp*/
#include "header.h"
#include "header.h"
#include "header.h"
#include "header.h"
#include "header.h"
//No problems! 

Oh yes you're right. Thanks!
Topic archived. No new replies allowed.