You could use templates:
template <typename T>
class ChannelInterface
{
public:
virtual QList<T*> getItems() = 0;
};
class storeChannelItem
{
// ...
};
class newsChannelItem
{
// ...
};
class storeChannel
: public QObject,
public ChannelInterface<storeChannelItem>
{
QList<storeChannelItem*> items;
public:
QList<storeChannelItem*> getItems();
};
class newsChannel
: public QObject,
public ChannelInterface<newsChannelItem>
{
QList<newsChannelItem*> items;
public:
QList<newsChannelItem*> getItems();
};
template <typename T>
class ChannelInterface
{
public:
virtual QList<T*> getItems() = 0;
};
class storeChannelItem
{
// ...
};
class newsChannelItem
{
// ...
};
class storeChannel : public QObject, public ChannelInterface<storeChannelItem>
{
QList<storeChannelItem*> items;
public:
QList<storeChannelItem*> getItems();
};
class newsChannel : public QObject, public ChannelInterface<newsChannelItem>
{
QList<newsChannelItem*> items;
public:
QList<newsChannelItem*> getItems();
};
To copy to clipboard, switch view to plain text mode
EDIT: Don't forget to define a virtual destructor in your interface also:
template <typename T>
class ChannelInterface
{
public:
virtual ~ChannelInterface() {}
virtual QList<T*> getItems() = 0;
};
template <typename T>
class ChannelInterface
{
public:
virtual ~ChannelInterface() {}
virtual QList<T*> getItems() = 0;
};
To copy to clipboard, switch view to plain text mode
Bookmarks