Results 1 to 6 of 6

Thread: Creating a global array in my code???

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Creating a global array in my code???

    hey there i have created a global array in my file but when i try to access it (i.e. array[0] = 25), the program crashes when i run it. ive heard of a method called a singleton pattern?? is this the best way to go about creating a global array in my code? any help or advice would be much apreciated, thanks. Jag

  2. #2
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a global array in my code???

    Quote Originally Posted by therealjag
    ive heard of a method called a singleton pattern??
    http://www.qtcentre.org/forum/showthread.php?t=465 Avoid global variables if possible

  3. #3
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Creating a global array in my code???

    The Singleton pattern is for making sure a class only has one instance ... and can be accessed globally. You could let a class manage this data for you and possible encapsulate the type.

    IMHO arrays are a error-prone way to manage data. Use a std::vector instead.

    Do a search ... you'll find numerous online examples of the Singleton pattern. Here's the book from GoF:

    Design Patterns
    ISBN 0-201-63361-2
    by Gamma, Helm, Johnson, Vlissides

  4. #4
    Join Date
    Mar 2006
    Posts
    22
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Creating a global array in my code???

    How exactly have you created it?

  5. #5
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Creating a global array in my code???

    Quote Originally Posted by dublet
    How exactly have you created it?
    It's created when you call SingletonClass::getInstance() -- which is a class-scope method (static method in C++).

  6. #6
    Join Date
    Mar 2006
    Posts
    22
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Creating a global array in my code???

    Quote Originally Posted by brcain
    It's created when you call SingletonClass::getInstance() -- which is a class-scope method (static method in C++).
    I was referring to the global array, not the singleton.

Similar Threads

  1. Creating Qgraphics View code
    By amagdy.ibrahim in forum Qt Programming
    Replies: 9
    Last Post: 15th June 2008, 15:43
  2. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41
  5. creating a global instance
    By skatakam in forum General Programming
    Replies: 6
    Last Post: 24th February 2006, 16:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.