DevHeads.net

C++ multiple classes doing similar stuff

In isoimagewriter I've multiple classes doing ISO verification. How
this is done differs per distro so I've different classes for Neon,
Kubuntu, Arch etc. They share a common parent class to not duplicate
too much code. But I still need to create each class and call it
individually.

In a more dynamic language I'd make an array of these classes for loop
over the array to call them. What's a good way to do something
similar in c++?

I worry the answer will include templates and other scary parts of c++.

Jonathan

Comments

Re: C++ multiple classes doing similar stuff

By Daniel Nicoletti at 08/04/2017 - 13:13

2017-08-04 13:51 GMT-03:00 Jonathan Riddell < ... at jriddell dot org>:

What's a good way to do something
QVector<ParentClass *> verifiers;// or std::vector
// push_back each instance
for (ParentClass *foo : verifiers) {
foo->someVirtualThatIsOverriden();
}

I don't think there's something wrong with this.