although I've been helped countless times by other questions/answers here, this is my first question here, so don't be too harsh on me! :)
I've been learning QT/C++ and let's assume I have something like this:
class AbstractMasterClass{
public:
virtual void foo(void) = 0; //Pure virtual method
}
This class will have plenty subclasses, each one of them implementing their own foo() method. And the question is: How can I create a QList which I'll populate with AbstractMasterClass's subclasses?
The objective is to be able to iterate through the list calling the foo() method for every element, i.e. use the master class the same way I would do to a Java interface. The few tries I ended up getting several compile time errors saying that we can't allocate an object of an abstract class (obviously) while creating the QList.
So how can I do it or is there a better way to make a java like interface in C++/QT?
Thank you all in advance for your time answering or pointing me in the right direction!
std::shared_ptr
orstd::unique_ptr
may be better thanQSharedPtr
. – Mullens