Results 1 to 2 of 2

Thread: Forward Class declaration ERROR

  1. #1
    Join Date
    Jun 2007
    Posts
    21
    Thanks
    25
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Forward Class declaration ERROR

    Hi,

    Within my application class header i have implemented global forward class declaration as follows:

    #include bla

    class Prep;
    Prep* pPrep;

    class Prep : public QMainWindow
    {

    ....

    };

    When compiling im getting to following error messages:
    .obj/main.o/user/lib/qt3/include/qglist.h first defined here line 150
    .obj/navTopDlg.o:/usr/lib/qt3/include/qglist.h multiple definition of pPrep line 150
    /usr/lib/qt3/include/qglist.h multiple definitions of pntPrep line 150

    was just wondering if anyone knew anything about this problem with qglist when making forward class declarations.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Forward Class declaration ERROR

    You can't instantiate a forward declared class until the class definition for that class has been encountered by the linker.

    Try declaring it with extern. Should work. Basically you are telling the linker that this class is defined in some object file, forcing external linkage. You are just using it here.

    But, the bottom line is that instantiating objects in headers is not a good practice.
    Do you really need that object in all the cpp files in which the header will be included? It is hard to believe.
    There is a programming pattern, called Singleton. I think this best suites your needs if you need a single instance of an object across an application.
    You just create a class with a private constructor and a getter function which returns the single instance of this class.
    You can find more about it on the internet.

    Regards

  3. The following user says thank you to marcel for this useful post:

    nleverin (1st August 2007)

Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.