Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Class vs include
Forum Updated to NodeBB v4.3 + New Features

Class vs include

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 922 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    otttx33
    wrote on last edited by
    #1

    i'm reading the book "C++ Gui programming with Qt4" and i notice inside the code of the book,
    that sometimes inside the header files we use preprocessor command include:

    @#include <QDialogButtonBox>@

    and sometimes we use the declaration of class:

    @class QList;@

    Is there any rule when to use class and when to use class??

    Sorry for the question, and the language, and thanks in advanced.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Apelsinsaft
      wrote on last edited by
      #2

      In short, if the compiler doesn't need to know the size of an object or what methods it has, you can get away with not including the header - just do a forward declaration. For instance, if you declare a pointer to an object of a certain class, the compiler only needs to know that the class exists. If, however, you start calling methods on the object, the header has to be included.

      This was a short and simplified explanation, google for more info. Or brace yourself and read "this informative article":http://herbsutter.com/2013/08/19/gotw-7a-solution-minimizing-compile-time-dependencies-part-1/.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved