I have a large program that is working other then one .h file that gives me the error that I have “invalid use of undefined type” when I try to declare a private ofstream. In eclipse I also get the error about “declaration of struct std::ofstream” with an external ocation /user/include/c++/4.1.2/iosfwd (I cheked, that is the line/location that defines ofstream). I’ve included both iostreams and fstreams.
if I try to chage the declaration to use an ifstream or an fstream I will get the same errors, only now I’ll have an error on the declaration of whatever object type I tried to use.
To make things even more annoying I use fstream and ifstreams elsewhere in the program. At one point I got exasperated enough that I copy the full contents of a valid .h file using an ifstream into the .h file that gave me an error…and I got the same error. I don’t know why code valid in one file would be invalid in another file when the only change is the name of the file and the if_def macros. The two .h files reside in the same directory.
I’m sorry I can’t post the code to be reviewed. It’s written on a different computer with no way to transfer the code from computer A to B (and no internet access). But if you can provide a suggestion as to why I would get this error for me to test without viewing the code I would appreciate it.
EDIT: After playing around some more I learn if I remove the .H file from it’s CPP file error goes away. so if the file is named VectorOutput.h. if I remove the #include from VectorOutput.cpp, even if I include it in other files, eclipse doesn’t complain. If I change the name of VectorOutput.cpp in any way the error goes away too. Which is…bizzare. I have no clue what that could mean, the name and specific location of the files should mean nothing as far as I know. by renaming the file I sort of got rid of the issue for now, but I really awnt to know he underlying cause if anyone has a guess.
You provide little to go on. I would check your namespaces. Check that you are declaring your type correctly with the prefix std::.
EDIT:
Actually, if you are using the ofstream in your header (and you are since you are declaring it a member), you will have to include the fstream header. iosfwd is only good for forward declaring the types.