Results 1 to 5 of 5

Thread: Simple question about heritances

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Simple question about heritances

    Hi all, I have a class with functions A and B. Function A calls to B. Well, I need to subclass this class because I need to reimplement the function B (the function A remains the same). The question is: in the new class, when A calls to B wich "version" of B is called: the "new" or the "old" one. If the answer is the version from the parent class (as I think) what's the best solution to make that the function A calls to the new B in the subcalassed class? Defining B as virtual in the parent class and reimplement it in every subclass, maybe?

    Thanks.

  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: Simple question about heritances

    Quote Originally Posted by SkripT
    Defining B as virtual in the parent class and reimplement it in every subclass, maybe?
    Yes, but you don't have to reimplement it everywhere.

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Simple question about heritances

    Quote Originally Posted by jacek
    Yes, but you don't have to reimplement it everywhere.
    Do you mean jacek that If I define B in the main class as virtual but I also implement it, it will work as I need?

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple question about heritances

    in both classes declares B as virtual and reimplement it then everything will work fine : that's the point of dynamic function linking.
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Simple question about heritances

    Thanks both!

Similar Threads

  1. a simple noob question
    By wrproject in forum Newbie
    Replies: 1
    Last Post: 1st July 2008, 23:25
  2. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  3. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02
  4. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 22:37
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

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.