First of all, I know that variadic functions can't be virtual in c++. My question is how to emulate the next "incorrect" example. I want to have a class A with "virtual variadic function" and class B which inherits it and implements only "part of it":
class A {
template<class... Types>
virtual void f(Types... buffers) { return; }
};
class B : public A {
// Overrides only 2 options of "generic" f
void f(unsigned char* buff2) override;
void f(unsigned char* buff1, unsigned int* buff2) override;
};
In my use case it is very important to have this generic f call but different classes only support "subsets" of variadic function f:
A* a= factory(...);
a->f(buff1, buff2, buff3); // OK
a->f(buff1); // OK
a->f(buff1, buff2); // Error! Factory gave an instance which does not support this call
It sounds like you are looking for
std::any.However your requirements imply a horrible design problem. Someone who is given an
Acan't know what they can do with it without knowing what subclass it actually is, at which point they should have a reference to that type, instead.