You can use a variant
:
std::vector<boost::variant<
boost::math::normal_distribution<double>,
boost::math::students_t_distribution<float>
> > v;
boost::math::normal_distribution<double> n;
boost::math::students_t_distribution<float> t(4);
v.push_back(n);
v.push_back(t);
I have several answers that show how to use these elements "polymorphically" (though the polymorphism is by statically compile typeswitching, instead of vtable dispatch). I'll add a link or two soon.
- Generating an interface without virtual functions?
- Avoid RTTI when dealing with pairs of objects
- More involved: boost::mpl::fold for double parameter abstraction
Some of the linked answers show the "manual" approach to type erasure
PS. I should probably mention boost::any
too, but I dislike it for several reasons. I shan't recommend it for this purpose.