c++ header file

Hi to all,
As iam stuck up with my program and i need some to complete that one. I wrote two programs for binary search tree in graphics. one program is for binary search tree and the other one for welcome note. i have to combine both the programs as a single program. I did adding welcome note in other program as a header file. But it is giving errors.. and i need help on this...
Exactly how the hell do you think we can help you when your post is not clear and you have not provided any code??
You can't really execute code out of a header file directly (ie main in a header). It doesn't get compiled.
And I totally agree with Return 0. Why don't you take a look at this before asking such a lacking question again: http://www.cplusplus.com/forum/beginner/1/
Last edited on
Return 0: you are supposed to use ESP to divine the errors and what the code looks like...
Which IDE are you using?

in general add both source files (cpp) under same project and build complete project you will have a common obj for your entire program having code from both the files and the exe if thts for win32 env.
make sure you have just one main method in one file only (files which are in same project namespace/region)
You can't really execute code out of a header file directly (ie main in a header). It doesn't get compiled.

You can. It gets compiled because it gets included. When you #include something, the compiler preprocessor searches your PATH for header files that match, and when it finds them, it copies the contents into your file, presumably at the place you put #include <foo>
Last edited on
chrisname is right.

i just executed this:
1
2
3
4
5
6
7
// Head.h
#include<stdio.h>

void main()
{
	printf("hello");
}


1
2
3
4
//source
#include "Head.h"



this gives output :
hello
Yea.. "Head.h" and "Head.cpp" are just names You don't have to name your files in any specific manner. Some people prefer "Head.cc" for implementation files, some use "Head.hpp" for headers. The standard omits file endings totally for most header files ("iostream")

The point about this is: The thing we call "header files" are meant to be included from many (at least more than one) different other files, which in turn we call "source files". If you do this with your example, you will see your linker starts to complain about multiple functions "main".

Anyway, all this is pretty basic stuff and I guess you get a lot better help in the beginner's forum - also for the original problem you had with the "combined programm". But better post some source code there as well (use [ code] before and [ /code ] after your source to make it look pretty.)
That's fine, but don't use void main(). I've said it about five times in as many days...
Topic archived. No new replies allowed.