![]() |
|
|
#1 | ||
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
C++: What's wrong with this header file?
Code:
Everything works if I don't pass anything to the function otherwise the compiler screams with: Code:
Code:
Code:
Last edited by Karim : 01-27-2005 at 01:05 AM. |
||
|
|
|
|
|
#2 |
|
General Manager
Join Date: Oct 2000
Location: The Satellite of Love
|
Shouldn't the includes for iostream and fstream be in the header file instead of the .cpp file? If you don't put them in the header, then the compiler doesn't know what ofsteam is for the parameter type. At least, I don't think it would.
|
|
|
|
|
|
#3 |
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
Thanks, sab. The document I was working from only had simple examples so none of the sample header files had any #includes.
|
|
|
|
|
|
#4 |
|
SI Games
Join Date: Oct 2000
Location: Melbourne, FL
|
One thing to bear in mind for the future which might help with compile speeds if you work on large projects is 'forward declarations of classes'.
If a class is referenced in a header but its content isn't required for compilation (generally speaking if you're using pointers to it in the class functions or data) then you can forward declare a class. This is simply telling the compiler "don't panic the class exists and the linker will find it" and allows you to avoid having unrequired includes in header files. To do this use the syntax: class MY_CLASS; This indicates that a class called MY_CLASS exists and not to worry about its contents. (please note this is a basic overview of how 'forward declarations work' and isn't meant to be 100% correct in low level stuff to do with compilers) |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|