On 2005-04-08, Dave Mill <da******@davemill.com> wrote:
I have implemented a class which performs operations on some file
throughout different methods in the class.
I did this by making the ifstream a private class member and opening the
file in the constructor,
however someone told me this was bad practice to have the stream as a
class attribute.
Not sure why -- but here are two issues:
(1) you can't copy or assign. Not necessarily a problem, but depends on how
you're using it. You've got to think about whether the object you're modelling
can truly be "copied".
(2) stack space: sizeof(ifstream) is 280 on my compiler, so it's very waste
to create streams that you're not using
About (2): you can use pointer and dynamically allocate when you use it.
About (1): use a shared pointer if you want a working copy constructor and
assignment.
Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/