Web lists-archives.com

Re: C++ multiple classes doing similar stuff




2017-08-04 13:51 GMT-03:00 Jonathan Riddell <jr@xxxxxxxxxxxx>:
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'd do exactly what you described :)

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.


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

Jonathan



--
Daniel Nicoletti

KDE Developer - http://dantti.wordpress.com