Results 1 to 2 of 2

Thread: Dereferencing a NULL Pointer for staticMetaObject?

  1. #1
    Join Date
    Oct 2006
    Location
    Raleigh, NC
    Posts
    11
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Dereferencing a NULL Pointer for staticMetaObject?

    Hi,

    I'm stumped... how does this work? This piece of code is from qobject.h in the function qFindChildren. It looks like it dereferences a NULL pointer to get the staticMetaObject??

    Qt Code:
    1. reinterpret_cast<T>(0)->staticMetaObject
    To copy to clipboard, switch view to plain text mode 

    Thanks!
    Hua-Ying

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dereferencing a NULL Pointer for staticMetaObject?

    Well... not exactly, staticMetaObject is a static member, so you don't have to dereference anything to access it --- you just have to know the correct type. Before static methods were introduced into C++, that was a way to simulate them and in fact it's an equivalent of:
    Qt Code:
    1. T::staticMetaObject
    To copy to clipboard, switch view to plain text mode 
    I'm not sure why it was written that way, but it might have something to do with some limitations of one of the compilers Qt supports or maybe it allows compiler to do some optimizations.

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

    jpn (15th December 2006)

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.