Problem 1: I have the following code:
template<typename T, typename S>
class Base {
virtual void fun(const T& arg1, const S& arg2) = 0;
private:
T v1;
S v2;
};
class Derived1 : public Base<int, double> {
public:
virtual void fun(int &arg1, double &arg2) override {
// do some special stuff
}
};
class Derived2 : public Base<float, int> {
public:
virtual void fun(float &arg1, int &arg2) override {
// do some special stuff
}
};
I need to collect all references to these objects (Derived1 & Derived2) in a single vector to loop over them and invoke fun on each object.
Problem 2: Same problem, but base has variadic template parameters now
template<typename T, typename ... S>
class Base {
virtual void fun(const T& arg1) = 0;
private:
T v1;
std::tuple<std::vector<S>...> v2;
};
class Derived1 : public Base<int, double, int, int> {
public:
virtual void fun(int &arg1) override {
// do some special stuff
}
};
class Derived2 : public Base<float, int, double, double> {
public:
virtual void fun(float &arg1) override {
// do some special stuff
}
};
Is there a convenient way to collect all references to the Derived1 and Derived2 objects in a single vector?