I have the following structure of classes and a templated wrapper class.
class A {};
class B : public A {};
template<class T>
class Foo {
T val;
public:
Foo(T t) {val = t};
T get() {return val};
}
Now, I need a function to process the values stored in the template but I can not modify the template itself. What I want is a function with signature similar to
void process(Foo<A>*) {/* do something */}
and I want to use it like
B b; Foo<B> foo(b);
process(&foo);
However, this won’t work because the compiler does not know how to convert Foo<B>* to Foo<A>*. Is there any workarround to fix the process function?
Make
processa function template:Inside the function template you can use the typename
Tas if it was classA. The function template will then work for all calls withFoo<B>as well.