I have a method foo in class C which either calls foo_1 or foo_2. This method foo() has to be defined in C because foo() is pure virtual in BaseClass and I actually have to make objects of type C. Code below:
template <class T>
class C:public BaseClass{
void foo() {
if (something()) foo_1;
else foo_2;
}
void foo_1() {
....
}
void foo_2() {
....
T t;
t.bar(); // requires class T to provide a method bar()
....
}
};
Now for most types T foo_1 will suffice but for some types foo_2 will be called (depending on something()). However the compiler insists on instantiating both foo_1 and foo_2 because either may be called.
This places a burden on T that it has to provide a bar method.
How do I tell the compiler the following:
- if T does not have bar(), still allow it as an instantiating type?