I've got a class D
, that I want to have classes A,B,C
inherit from. However, the functions that I want to declare as pure virtual
are templated.
Unfortunately, in the words of visual studio:
member function templates cannot be virtual
Classes A,B,C
have a member operator called in the exact same manner, though may return different values (double
or unsigned int
namely. But I'd be happy to get it to work with just double
):
template<typename T>
double operator()(T&, unsigned int b){/*code*/};
How could I properly create a polymorphic collection of classes A,B,C
(similar to a std::vector<D*>
that would work if I didn't want member function templates) that does what I'm trying to do?
EDIT:
An example of what I'd like to be able to do:
std::default_random_engine rng((unsigned int) std::time(0));
std::vector<D*> v;
v.push_back(new A(0.3));
v.push_back(new B(1.0,3.2));
v.push_back(new C);
for(auto x : v){
for(auto y : x->operator()(rng,5){
std::cout << y << ',';
}
std::cout << std::endl;
}