So i have the following code:
typedef Shape *(createShapeFunction)(void);
The problem is that shape is a template so i would like it to be something like this:
typedef Shape<T> *(createShapeFunction)(void);
I have already tried the following
typedef template<typename T> Shape<T> *(createShapeFunction)(void);
template<typename T> typedef Shape<T> *(createShapeFunction)(void);
It gives me errors saying that this is not allowed. Can you please help?
Try this:
template<typename T>
struct ShapeFunctionPointers {
typedef Shape<T> (*createShape)(void);
};
ShapeFunctionPointers<int>::createShape f;
Note that for each type T
there will be a different function pointer type.
In C++11 you should be able to write:
template<typename T> using createShapeFunction = Shape<T> (*)(void);
createShapeFunction<int> f;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments