Results 1 to 7 of 7

Thread: Declaring a class as extern

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Declaring a class as extern

    I would suggest going with a singleton approach rather than using an extern global variable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    ehnuh (8th November 2012)

  3. #2
    Join Date
    Sep 2012
    Posts
    31
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Declaring a class as extern

    hi thanks for the replies. what would be the edge of the singleton approach over an extern global variable?

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Declaring a class as extern

    Quote Originally Posted by ehnuh View Post
    hi thanks for the replies. what would be the edge of the singleton approach over an extern global variable?
    Cleaner API, less error prone access and total control over when the variable is created and destroyed (a global variable is created before main() is executed and destroyed after main() returns). It also assures there is just one instance of the class in the whole program.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    ehnuh (8th November 2012)

  6. #4
    Join Date
    Sep 2012
    Posts
    31
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Declaring a class as extern

    thanks for the info! I have tried declaring and defining the extern class variable in one pro file. Since I have multiple pro files, I want to access the CFacade FacadeObj I declared and defined. I just add the header of the FacadeObj to the cpp files found in the other pro files (I also added a header for a global shared library since it will be declared in another pro file)...I am not sure what I am still missing but when I build the whole subdirs proj, the

    FacadeObj I used in the pro file is undefined. The error is "undefined reference to Facadobj"

Similar Threads

  1. Problems compiling when using an extern
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2011, 12:32
  2. Extern Variable linkage error
    By mebingj in forum Newbie
    Replies: 3
    Last Post: 26th January 2011, 12:06
  3. extern QWidgetList *qt_modal_stack
    By Alex_123 in forum Qt Programming
    Replies: 5
    Last Post: 20th December 2008, 12:24
  4. extern class
    By zorro68 in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2007, 21:08
  5. problem declaring a class
    By mickey in forum General Programming
    Replies: 1
    Last Post: 26th May 2006, 18:12

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.