Creating Hedaer files for C++

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
dream_coder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Sat Mar 27, 2010 5:16 pm

Creating Hedaer files for C++

Post 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
}
Image
Image
Image
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Creating Hedaer files for C++

Post 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.
dream_coder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Sat Mar 27, 2010 5:16 pm

Re: Creating Hedaer files for C++

Post 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.
Image
Image
Image
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Creating Hedaer files for C++

Post 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. ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply