CFileHandler's ifs member
Moderator: Moderators
CFileHandler's ifs member
Why does CFileHandler use an std::ifstream* instead of just an std::ifstream? https://github.com/spring/spring/blob/7 ... dler.h#L73
Re: CFileHandler's ifs member
Go back in time about eight years (FileHandler is that old) so you can ask the original author.
Any reason this particular file holds your interest?
Any reason this particular file holds your interest?

Re: CFileHandler's ifs member
Yes, I saw, I checked the history. It holds my interest because it's peculiar, has no comment, and I am interested in starting with Spring development, mostly to help clean up code
I'm actually rather interested in working on http://springrts.com/wiki/GSoC_New_rendering_system , but perhaps I should start small to learn Spring.

Re: CFileHandler's ifs member
The probable reason is the the original author thought that you need to know about the associated file to construct the object.
Re: CFileHandler's ifs member
No, the original author was smart and didn't included <ios> or <fstream> in the header and so speedup the compilation time.
Re: CFileHandler's ifs member
Actually, he did include <ios>. And anyway, <ios> isn't enough; it was just good fortune that it worked. std::ifstream is defined in <fstream>, and you're not allowed to forward declare stuff in std at all.
Re: CFileHandler's ifs member
You don't need to include anything when you use pointers in headers. The includes are then only needed where the implementation happens (.cpp). The <ios> was added for an additional function param of Seek().Muon wrote:Actually, he did include <ios>. And anyway, <ios> isn't enough; it was just good fortune that it worked. std::ifstream is defined in <fstream>, and you're not allowed to forward declare stuff in std at all.
Re: CFileHandler's ifs member
No, in most cases, you only need to forward declare the types. But as I said, you are not allowed to forward declare things in std, hence including <fstream> is necessary either way.jK wrote:You don't need to include anything when you use pointers in headers. The includes are then only needed where the implementation happens (.cpp). The <ios> was added for an additional function param of Seek().Muon wrote:Actually, he did include <ios>. And anyway, <ios> isn't enough; it was just good fortune that it worked. std::ifstream is defined in <fstream>, and you're not allowed to forward declare stuff in std at all.
Re: CFileHandler's ifs member
Forward declarations (or include directives) are only needed if you want a header to be compilable by itself:
Regardless of whether this would be bad practice, STL headers do tend to drag in a lot of crap, and gcc already isn't all that fast.
Code: Select all
// bla.hpp (*no* includes, *no* fwddecs)
void f(std::fstream*);
// bla.cpp
#include <fstream>
#include "bla.hpp"
Re: CFileHandler's ifs member
Well, sort of. You can't actually include that header and still have the .cpp compile without a declaration of std::ifstream somewhere, making that kinda useless. As a rule, include only what you need, but include everything you need. If I actually wanted just a pointer/reference, I would just include <iosfwd>, as it provides forward declarations for all iostreams.