Results 1 to 8 of 8

Thread: Inhertiting QPtrList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cesar Guest

    Default Re: Inhertiting QPtrList

    Correct me, if I'm mistaken, but this code
    Quote Originally Posted by sunil.thaha
    Qt Code:
    1. //DataList.h
    2. template <typename T>
    3. class DataList : public QPtrList< T > {
    4.  
    5. public:
    6. DataList(){};
    7. // [Skip]
    8. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //DataList.cpp
    2. template < typename T >
    3. DataList<T>::DataList()
    4. :m_iLastError( QueryResult::ErrorNotSet ) {}
    5. //[Skip]
    To copy to clipboard, switch view to plain text mode 
    should lead to link error, as Datalist<T>::Datalist() is implemented twice: both in header and in .cpp files. I suggest something like this:
    Qt Code:
    1. //DataList.h
    2. template <typename T>
    3. class DataList : public QPtrList< T > {
    4. public:
    5. DataList();
    6. // [Skip]
    7. };
    8.  
    9. //DataList.cpp
    10. template < typename T >
    11. DataList<T>::DataList() :
    12. QPtrList<T>(),
    13. m_iLastError( QueryResult::ErrorNotSet )
    14. {
    15. }
    16. //[Skip]
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Inhertiting QPtrList

    Quote Originally Posted by Cesar
    Correct me, if I'm mistaken, but this code
    those Errors were resolved

    Quote Originally Posted by Cesar
    Qt Code:
    1. //DataList.cpp
    2. template < typename T >
    3. DataList<T>::DataList() :
    4. QPtrList<T>(),
    5. m_iLastError( QueryResult::ErrorNotSet )
    6. {
    7. }
    8. //[Skip]
    To copy to clipboard, switch view to plain text mode 
    But do we need to call the Base Constructor Explicity
    Last edited by sunil.thaha; 8th February 2006 at 13:41.
    We can't solve problems by using the same kind of thinking we used when we created them

  3. #3
    Cesar Guest

    Default Re: Inhertiting QPtrList

    Quote Originally Posted by sunil.thaha
    But do we need to call the Base Ponter Explicity
    Hm... Frankly saying, I'm not sure, anyway that won't hurt . I suppose the behaviour is compiler-dependent, so doing something explicitly should make the code more portable... I guess

  4. #4
    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: Inhertiting QPtrList

    No I don't think so. I have read that When a DErived object is created, the Derived Construtor will call the default constructor of the Base
    We can't solve problems by using the same kind of thinking we used when we created them

Similar Threads

  1. Removing items from QPtrList efficiency issues
    By kalos80 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2007, 13:04
  2. QList usage in place QPtrList
    By darpan in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 16:41

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.