I'm a Java guy where all you need is a .java file. What's the deal on the .h and .cpp files? Must you have both in a program (simple stuff mind you)? I know you need .cpp but what about the .h file?
I'm a Java guy where all you need is a .java file. What's the deal on the .h and .cpp files? Must you have both in a program (simple stuff mind you)? I know you need .cpp but what about the .h file?
i don't think you actually need .h (but i would suggest to use .h). i think you could really just have a bunch of .cpp files and making use of the keyword "extern" a lot.
So why is the .h file there and what purpose does it serve?
A header file is best used to declare class and function prototypes. When you #include them, the preprocessor adds them to the code, so therefore you dont have to replicate every object and function to use it within your source.
They can be used with .cpp files or precompiled libraries....
For precompiled libraries, they can be usefull for you to give an indication of what your class does without having to give away the full source code and implementation.
Have a look in any C++ book for information on this.
Ah ok. So something like the iostream could be brought in as a header file instead of #include iostream in your .cpp file? Would there be any advantage do doing it like that or should you stick with the include?
-Edit: Just to explain, I'm not ready to start learning C/C++ yet. I've still got so much to learn in Java before I'd feel confortable starting something new. I'm trying to understand some of the mindset and logic of C/C++ before I do get started, whenever that may be.
Last edited by CompiledMonkey; 02-15-2002 at 09:37 AM.