Hi having only recently started programming in C++ i have got to the stage that i have made my own header file but cant get it to work.It is saved where the rest of my source is.And shows up there as a headerfile(although it says its C and not C++?)When I include it in my main none of the functions work.
Im using Dev-C++ ver.4.9.9.2
windows vista.
Heres the header file code in case the fault is there:
ifndef myfunctions.h
define myfunctions.h
//diceRoll function
int diceRoll( int sides, int num_dice )
{
int sum = 0;
for( int i = 0; i < num_dice; ++i)
sum += rand() % sides + 1;
returnsum;
}
//playerdam
int playerdam(int &gobHealth)
{
int dam=diceRoll(10,1);
gobHealth-=dam;
return dam;
}
//gobdam
int gobdam(int &playerHealth)
{
int dam=diceRoll(10,1);
playerHealth-=dam;
return dam;
}
endif
and in my main i try and include it :
include<iostream>
include<ctime>
include<myfunction.h>
I hope i have explained it ok.any help much appreciated
lbmouse
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks old newbie that done the trick.Does it matter that my header file is showing as a C header file and not a C++ one?
Labmouse
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-09-03
No. If you include it in a .cpp file and teh C++ compiler is used to compile it, it is a C++ header! You could use .hpp as the extension if you wish, but few use that convention.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-09-03
Try
include "myfunction.h"
Good luck
Old Newbie
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-09-03
include <...> will only look in the folders specified by -I compiler options, wheras #include "..." will look in the folder containing the file being compiled first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi having only recently started programming in C++ i have got to the stage that i have made my own header file but cant get it to work.It is saved where the rest of my source is.And shows up there as a headerfile(although it says its C and not C++?)When I include it in my main none of the functions work.
Im using Dev-C++ ver.4.9.9.2
windows vista.
Heres the header file code in case the fault is there:
ifndef myfunctions.h
define myfunctions.h
//diceRoll function
int diceRoll( int sides, int num_dice )
{
int sum = 0;
for( int i = 0; i < num_dice; ++i)
sum += rand() % sides + 1;
}
//playerdam
int playerdam(int &gobHealth)
{
int dam=diceRoll(10,1);
gobHealth-=dam;
return dam;
}
//gobdam
int gobdam(int &playerHealth)
{
int dam=diceRoll(10,1);
playerHealth-=dam;
return dam;
}
endif
and in my main i try and include it :
include<iostream>
include<ctime>
include<myfunction.h>
I hope i have explained it ok.any help much appreciated
lbmouse
Thanks old newbie that done the trick.Does it matter that my header file is showing as a C header file and not a C++ one?
Labmouse
No. If you include it in a .cpp file and teh C++ compiler is used to compile it, it is a C++ header! You could use .hpp as the extension if you wish, but few use that convention.
Thanks again,
Labmouse
Try
include "myfunction.h"
Good luck
Old Newbie
include <...> will only look in the folders specified by -I compiler options, wheras #include "..." will look in the folder containing the file being compiled first.