I've just tryied it but figura<float> is different from figura<int> so there was an error like
Well you are not going to be able to assign anything other than a figura<float>*, or a subclass thereof to your variable fig. What are you trying to do? Can you post the rest of your code, or at least get_figure<>()?
Templates are not used for runtime polymorphism, which appears to be what you are doing with your
switch statement. Although there are solutions, I would recommend eschewing the template-based
approach.
@TiaSorella
I have looked at your code and you are trying to do things using templates that they were not designed for. Whatever your teacher is asking, I don't think he is expecting you to solve it in this way. Templates can be useful in this but I think you need to rethink your approach. What exactly is the teacher asking you to do?
Could you post your code here? It would also be useful if you posted the contents of the file.
Use code tags for your code -> [code]your code here[/code].
It seems to me that the abstract factory pattern could be of use here.
The concrete factories would be template instantiations for specific primitive types.
I have to use a method area() that must be templated...I put it into my template class : figure, triangle, circle etc.
But if I use a non-templated class shape I can't declare in it a method " virtual void area()= 0 " [there is a problem of overrinding when i declare " T area() " into SahpeT ...
An other solution will be to put a method " T area( shape *) " into MyAppT but it will be longer and little uggly..
The simple solution is to make area print the result instead of returning it. I think this would be enough for this exercise. There are probably other ways, but I believe all of them are ugly. I'll keep thinking though... And maybe someone else knows better...
yeah but i have to do any computation whit the analitycs area.
Anyway I think it's enought to use long double as return type of the area() method and casting (C's style) the value before returning directly into the implementetion of area() in triangolo.cc etc.