I have this piece of code:
#include <iostream>
#include <string>
#include <vector>
class MyAbstract
{
public:
std::string id;
virtual void doStuff() = 0;
virtual ~MyAbstract() {}
};
int main()
{
std::vector<MyAbstract> myList;
for(auto item : myList)
{
//DoSomething
}
}
But it doesn't compile with this error:
error: cannot allocate an object of abstract type 'MyAbstract'
Visual Studio 2015 Error:
cannot instantiate abstract class
Here is the code online: http://cpp.sh/3etnq
What am I missing here?! This works:
for (auto it = myList.begin(); it != myList.end();)