View Full Version : inheritance, pure virtual

18th January 2007, 11:09
Hello all,

I'd like to make a abstract base class with one pure virtual function. Let's say it looks like this:

class BuddyBase : public QWidget
BuddyBase(QWidget* parent = 0);
virtual ~BuddyBase();
virtual void update (QString text) = 0;
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?


18th January 2007, 11:13
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.

18th January 2007, 11:20
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