Thread: static variables

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    29

    static variables

    I have this statement inside a function, that opens a XML file.

    Code:
    static auto_ptr<Remote> remoteXML (Remote_("../config/remote_conf.xml"));
    The XML file is opened every-time I call the function or is opened only in the first call??

  2. #2
    Novice
    Join Date
    Jul 2009
    Posts
    568
    I believe that it will be open every time.

    static, in this case, will just make this function invisible to other program modules (e.g. files).

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    No, static variables inside functions don't make the functions static itself. This will be opened only in the first call.
    And I wouldn't make it this way, since you will not be able to use this variable outside the function. It looks like the function does not open an XML file, but only creates an instance of object. You should consider returning a shared_ptr<Remote> so you will be able to open more than one file at a time.
    Last edited by kmdv; 09-05-2010 at 09:01 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static variables + Initialisation
    By kris.c in forum C Programming
    Replies: 2
    Last Post: 07-08-2007, 02:16 AM
  2. Static variables
    By ashughs in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2006, 09:21 AM
  3. static variables
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2006, 06:35 AM
  4. Visual C++ 6/.net Debug static variables
    By neandrake in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2005, 03:45 AM
  5. Replies: 5
    Last Post: 11-19-2002, 07:49 PM