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. QScopedPointer uses delete []
Forum Updated to NodeBB v4.3 + New Features

QScopedPointer uses delete []

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 567 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.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1

    Why QScopedPointer uses delete [] instead of simpledelete?

    template <typename T>
    struct QScopedPointerArrayDeleter
    {
        static inline void cleanup(T *pointer)
        {
            // Enforce a complete type.
            // If you get a compile error here, read the section on forward declared
            // classes in the QScopedPointer documentation.
            typedef char IsIncompleteType[ sizeof(T) ? 1 : -1 ];
            (void) sizeof(IsIncompleteType);
    
            delete [] pointer;
        }
    };
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      http://doc.qt.io/qt-5/qscopedpointer.html#custom-cleanup-handlers
      You chose what to use by specifying the second template argument.
      QScopedPointer<int> uses delete
      QScopedPointer<int,QScopedPointerArrayDeleter> uses delete []

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

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