Results 1 to 3 of 3

Thread: inheritance, pure virtual

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default inheritance, pure virtual

    Hello all,

    I'd like to make a abstract base class with one pure virtual function. Let's say it looks like this:
    Qt Code:
    1. class BuddyBase : public QWidget
    2. {
    3. public:
    4. BuddyBase(QWidget* parent = 0);
    5. virtual ~BuddyBase();
    6. public:
    7. virtual void update (QString text) = 0;
    To copy to clipboard, switch view to plain text mode 
    I'd like to inheirit this, making a class that (of course) implements its own update(). But, I'd like to have
    update(double*), or, in some other case update(QVector), for instance.
    How can I do it?

    Do I have to declare
    virtual void update(class <T>)=0;
    or something?
    Will this be ok with the inheiritance of QWidget?

    thanks
    Kev

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: inheritance, pure virtual

    Quote Originally Posted by TheKedge View Post
    Do I have to declare
    virtual void update(class <T>)=0;
    This is not a good idea

    If you need all those variants to be pure abstract, then declare them in the base class. If that's not necessary (meaning that you don't have to call it using the base class API), just implement those methods in subclasses. An alternative is to use a union or QVariant as the method argument, so that you can handle all types in a single method.

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

    TheKedge (18th January 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: inheritance, pure virtual

    Ahh, of course ... how simple! - don't declare it at all (and implement subclasses) !
    thanks again for being so quick on the draw!
    good help - in real-time
    K

Similar Threads

  1. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 16:06
  2. How much inheritance do you use?
    By Michiel in forum General Programming
    Replies: 8
    Last Post: 1st August 2006, 22:29
  3. Inheritance and QpaintEvent
    By djoul in forum Qt Programming
    Replies: 22
    Last Post: 5th July 2006, 13:56
  4. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 21:26
  5. Multiple inheritance & Qt
    By dublet in forum Qt Programming
    Replies: 11
    Last Post: 8th March 2006, 08:12

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.