Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Why are pointer objects created while defining a class?

Why are pointer objects created while defining a class?

Scheduled Pinned Locked Moved Unsolved Qt WebKit
2 Posts 2 Posters 656 Views
  • 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.
  • S Offline
    S Offline
    Swati777999
    wrote on 2 Aug 2021, 01:52 last edited by
    #1

    Hi All,
    I hope that you're doing well .I've a doubt regarding the creation of pointer object of a class. I want to know why are pointer objects created in the definition of a class instead of simply creating an object of that class.

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    J 1 Reply Last reply 2 Aug 2021, 03:46
    0
    • S Swati777999
      2 Aug 2021, 01:52

      Hi All,
      I hope that you're doing well .I've a doubt regarding the creation of pointer object of a class. I want to know why are pointer objects created in the definition of a class instead of simply creating an object of that class.

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 2 Aug 2021, 03:46 last edited by
      #2

      @Swati777999 said in Why are pointer objects created while defining a class?:

      I want to know why are pointer objects created in the definition of a class instead of simply creating an object of that class.

      There can be multiple different reasons. Some reasons are:

      1. To save space. The size of a pointer is always 32 bits or 64 bits (4 bytes or 8 bytes) on today's common PCs, but the size of a class/struct depends on the sizes of all its members. If an object is too big, it cannot be created on the stack (or it becomes easier to trigger a stack overflow).
      2. Because some objects cannot be copied. For example, you cannot have QList<QWidget>; you must use QList<QWidget*>
      3. Because of style/convention. Qt uses pointers to show that an object is an Identity object, and it uses non-pointers to show that an object is a Value object: https://doc.qt.io/qt-6/object.html#qt-objects-identity-vs-value

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2

      1/2

      2 Aug 2021, 01:52

      • Login

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