Results 1 to 3 of 3

Thread: Odd Syntax

  1. #1
    Join Date
    Oct 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Odd Syntax

    I haven't coded C++ in around five years so is it some sort of new syntax convention when you do this in your header files, or is it a QT thing?

    /// somefile.h

    #include <QLibrary>

    class Classname;
    class SomeOtherClassname;


    class YourClass {
    private:
    // etc
    public:
    //etc
    };

    The bold underlined part is the one that's new to me.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Odd Syntax

    These are forward declarations.
    You tell the compiler that those types are classes.
    This is enough to use the type in declarations, define pointers or references to the type.
    (It is not enough to derive from the type, or use it in another manner that requires knowledge about its size, its methods or any other things that are defined by a class definition.)

    Reason: you do not have to include the header where that class is defined.
    Thus you avoid a dependency and get quicker compile times.

    HTH

  3. #3
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Odd Syntax

    That's a forward declaration - its not just a Qt thing.

Similar Threads

  1. Building and using SSL with QSslSocket
    By nopcode in forum Installation and Deployment
    Replies: 3
    Last Post: 22nd October 2008, 10:25
  2. StyleSheet syntax checking
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 10:09
  3. QPaintEvent syntax question
    By last2kn0 in forum Newbie
    Replies: 5
    Last Post: 25th January 2008, 20:36
  4. Refreshing syntax highlighting
    By jpn in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2006, 20:09
  5. #ifndef syntax error
    By cbeall1 in forum Qt Programming
    Replies: 6
    Last Post: 14th February 2006, 09:29

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.