Page 1 of 1

Creating Hedaer files for C++

Posted: Sun Apr 04, 2010 8:31 am
by dream_coder
Hey all, I am trying to create a Header file for my C++ program. However I keep on getting the following error message

Code: Select all

c:\users\cyberstu\documents\visual studio 2008\projects\project_stu\project_stu\functions.h(34) : fatal error C1070: mismatched #if/#endif pair in file 'c:\users\cyberstu\documents\visual studio 2008\projects\project_stu\project_stu\functions.h'
Here is the code for the header file. I havnt yet added code to the functions I was just checking it would compile in case there were some really obvious mistakes so far.

Code: Select all

//Header guards

#ifndef ADD_H 
#define ADD_H 


int DrawMenu();
void CreateChar();
void LoadGame();
void NewGame();


int DrawMenu()
{
//Some code here

}

void CreateChar()
{
	//Some code here
}

void LoadGame()
{
	//Some code here
}

void NewGame()
{
	//Some code here
}

Re: Creating Hedaer files for C++

Posted: Sun Apr 04, 2010 8:35 am
by Falco Girgis
You're missing an #endif preprocessor directive at the end of your header file. Just add this at the very bottom:

Code: Select all

#endif
Your entire header file (without the endif) is essentially:

if(not defined) {
//your stuff

You never closed the brace.

Re: Creating Hedaer files for C++

Posted: Sun Apr 04, 2010 8:46 am
by dream_coder
Cheers for that. It compiles fine now. Just regret spending an hour looking at tutorials on google now, as it was so simple to solve.

Re: Creating Hedaer files for C++

Posted: Mon Apr 05, 2010 1:43 pm
by Ginto8
dream_coder wrote:Cheers for that. It compiles fine now. Just regret spending an hour looking at tutorials on google now, as it was so simple to solve.
Don't regret it. You probably learned some stuff that you wouldn't have otherwise, even though it may not have solved your current problem. ;)