class definition declaring ifstream object

This is a discussion on class definition declaring ifstream object within the C++ Programming forums, part of the General Programming Boards category; what is wrong with the ifstream declaration here?? i am missing something basic i think, the error is 'ifstream does ...

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438

    class definition declaring ifstream object

    what is wrong with the ifstream declaration here?? i am missing something basic i think, the error is 'ifstream does not name a type'

    Code:
    #ifndef NONSTATE_CLASSES_H_INCLUDED
    #define NONSTATE_CLASSES_H_INCLUDED
    #include <fstream>
    
    class PreviewBoards         //rem, i must create Global object
    {
        private:
    
        SDL_Surface* temp;
        SDL_Surface* Savesource;          //the save preview windows
        SDL_Surface* Minipieces;
        SDL_Rect savewin[6];
        SDL_Rect minipeg[49];
        SDL_Rect miniclip[49];
    
        ifstream Gamefile[6];
    
        int count;
        int dwn;
        int acr;
    
        public:
    
        PreviewBoards(int preview);
        ~PreviewBoards();
    };
    
    
    #endif // NONSTATE_CLASSES_H_INCLUDED

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    You should qualify the name, i.e., std::ifstream. Incidentally, if you can use a std::istream instead of a std::ifstream, then you might as well do so.

    I note that I/O streams are not copyable, hence objects of your PreviewBoards class will also not be copyable when you have input streams as members.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438

    .

    You should qualify the name, i.e., std::ifstream
    i did use that and it threw an absolute rack of errors, but if that is the right way then i should check other files for problems.

    I note that I/O streams are not copyable, hence objects of your PreviewBoards class will also not be copyable when you have input streams as members.
    I am better off creating the stream local to the constructor then? the object is only used once to show a set of saved game preview windows, the actual loading and saving uses a different stream elsewhere

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    Quote Originally Posted by rogster001
    I am better off creating the stream local to the constructor then? the object is only used once to show a set of saved game preview windows, the actual loading and saving uses a different stream elsewhere
    Not necessarily. Do you need the object to be copyable? It sounds like a no, and perhaps some other member variables are not copyable as well. If so, consider disabling the copy constructor and copy assignment operator by declaring them private: it more clearly signals that objects of the class are not copyable, and may also give better error messages if an attempt is made to copy.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    Not necessarily. Do you need the object to be copyable? It sounds like a no, and perhaps some other member variables are not copyable as well. If so, consider disabling the copy constructor and copy assignment operator by declaring them private:
    this might be the best route then, this object is not copied and it only requires an int arg to be passed in once. no other interaction takes place

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is there a way to tell what class an object is?
    By Loduwijk in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2006, 09:20 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. Replies: 3
    Last Post: 12-03-2001, 01:45 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21