Results 1 to 4 of 4

Thread: Pimpl implemenation - compilation error on static_cast base* to Derieved*

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Pimpl implemenation - compilation error on static_cast base* to Derieved*

    Is this very simple that no one want to answer ? or
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: Pimpl implemenation - compilation error on static_cast base* to Derieved*

    You can't define the function there, since at that point the compiler doesn't know that QstObjectPrivate inherits PrivateData you have to implement it at the end of the file:
    Qt Code:
    1. ...
    2. class QstObject : public PublicInterface
    3. {
    4. public:
    5. QstObject();
    6. private:
    7. inline QstObjectPrivate* data_pointer_test();
    8. };
    9.  
    10. class QstObjectPrivate : public PrivateData
    11. {
    12. public:
    13. QstObjectPrivate( PublicInterface *iface )
    14. : PrivateData( iface )
    15. {
    16. }
    17. };
    18.  
    19. QstObject::QstObject()
    20. : PublicInterface( new QstObjectPrivate(this) )
    21. {
    22. }
    23.  
    24. QstObjectPrivate* QstObject::data_pointer_test()
    25. {
    26. return static_cast<QstObjectPrivate*>( _data );
    27. }
    28. ...
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Pimpl implemenation - compilation error on static_cast base* to Derieved*

    Thanks a lot !!
    and that helped me make sense of why Qt's pimpl implementation uses reinterpret cast
    We can't solve problems by using the same kind of thinking we used when we created them

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
  •  
Qt is a trademark of The Qt Company.