Re: Implicit and Explicit Template Instantiation
First of all, the solution of Erik works. You still have to know the
type of data you're loading but you don't need to know the internal
storage type.
Rolf Magnus previously wrote the following e-mail:
Pierre Yves wrote:
I would like to create a class which can take either of the videos but I
got lost...
class Processor {
public:
Processor();
LoadData(Frame<T> * data);
protected:
Frame<T> * mydata;
}
What's T?
That's the problem. How can my processor type be compiled with the
proper type, when I pass it later on.
Frame<T> is the base class of data which is either video type.
My main would look like (the two videos should be usable):
int main(void) {
Video16bit * vid = new Video16bit();
// Video8bit * vid = new Video8bit();
Processor * pro = new Processor();
pro->LoadData(vid);
delete whatever is required;
}
The problem is that the creation of my processor depends on the type of
template and ... I dunno how to pass it cleanly.
That's because it's not possible that way.
How can I solve that?
My current solution is to template the Processor as well. However, I could
make a mistake of type: I would like the T of the processor defined by the
loaded video...
Does it make sense?
Yes, it does, but then you need polymorphism. Make a common base class with
the functions that differ virtual. Derive your two video classes from it.
Another way to see it would be: can I do a
Processor<vid->getType()> * pro> = new Processor();
No, you can't. Template arguments are fixed at compile time.
I know. However, there should be a way. I know that I should be able to
do that...
Basically, working on that, I reckon that having a templated member
force me to template the whole class...
Thanks Erik and Rolf for you help.
PY