I have a class similar to the following:
class SomeClass
{
public:
template<typename... Args>
void doSomething(Args && ... args);
};
However, I really want to have two different types SomeClass. Ideally, I could get a common interface for creating SomeOtherClass, but I need to have a different implementation doSomething, and the template methods cannot be virtual. I could make a template class, but then every method that accepts one of them (and there are many of them) must itself be templates, etc.
The best I could come up with was to implement both types doSomethingin the base class and call this method to determine the virtual method that will be used at runtime.
Is there a better solution?
Further explanation
I have many methods that look something like this:
void foo(SomeClass * obj);
foo obj->doSomething, , , SomeClass, , , :
class SomeClass
{
public:
template<typename... Args>
virtual void doSomething(Args && ... args) = 0;
};
class TheFirstType
{
public:
template<typename... Args>
void doSomething(Args && ... args);
};
class TheSecondType
{
public:
template<typename... Args>
void doSomething(Args && ... args);
};
, , . , doSomething, , TheFirstType TheSecondType, if, , :
template<typename... Args>
void SomeClass::doSomething(Args && ... args)
{
if (this->type() == FIRST_TYPE) {
} else if (this->type() == SECOND_TYPE) {
}
}
, , , .