How do i use typedef in c++ on a function pointer that must return an class template?

ciprianr

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?

Danvil

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

error C2823: a typedef template is illegal - function pointer

From Dev

How do I serialize a class containing pointer via a getter function?

From Dev

how to use void pointer as function return type In C

From Dev

Can I use a class level typedef as template argument for the base class?

From Dev

How do I use an extension function in another class? C#

From Dev

C++: How do I pass a pointer to a member function of another class?

From Dev

How do I call a C++ Class member function with the correct 'this' pointer like a normal C function? (pointer to class member function)

From Dev

How to create a "typedef to a function pointer" in C#?

From Dev

In C++ 11, how do I specialize a function template that takes a function object based on return type?

From Dev

How to typedef a function pointer with template arguments

From Dev

How do I declare a function that returns a pointer to a function that returns a function pointer without using a typedef in C?

From Dev

How to do a function pointer cast without a typedef?

From Dev

How do I use bind to pass a member function as a function pointer?

From Dev

typedef and pointer to function in C

From Dev

How do I return a pointer to a struct from a function?

From Dev

How to typedef a smart pointer wrapping a template class

From Dev

Use typedef member from a template class outside of the class as return type for member function

From Dev

How do I typedef a method pointer with the C++11 using syntax?

From Dev

How do I return a function pointer as const?

From Dev

how to pass pointer to member function of a template class?

From Dev

how do I specialize a bound template friend function to a template class?

From Dev

Template function pointer of template class - C++

From Dev

C++ typedef function definition as a class member to use later for function pointer?

From Dev

Typedef Template Class Pointer in*.cpp file

From Dev

C++ How can I call a template function with a template class?

From Dev

Typedef pointer in a Class Template

From Dev

How do I return a function pointer as const?

From Dev

C++ function template: Must use & for argument type and return type?

From Dev

How do I use typedef with class initializer parameters in C++?

Related Related

  1. 1

    error C2823: a typedef template is illegal - function pointer

  2. 2

    How do I serialize a class containing pointer via a getter function?

  3. 3

    how to use void pointer as function return type In C

  4. 4

    Can I use a class level typedef as template argument for the base class?

  5. 5

    How do I use an extension function in another class? C#

  6. 6

    C++: How do I pass a pointer to a member function of another class?

  7. 7

    How do I call a C++ Class member function with the correct 'this' pointer like a normal C function? (pointer to class member function)

  8. 8

    How to create a "typedef to a function pointer" in C#?

  9. 9

    In C++ 11, how do I specialize a function template that takes a function object based on return type?

  10. 10

    How to typedef a function pointer with template arguments

  11. 11

    How do I declare a function that returns a pointer to a function that returns a function pointer without using a typedef in C?

  12. 12

    How to do a function pointer cast without a typedef?

  13. 13

    How do I use bind to pass a member function as a function pointer?

  14. 14

    typedef and pointer to function in C

  15. 15

    How do I return a pointer to a struct from a function?

  16. 16

    How to typedef a smart pointer wrapping a template class

  17. 17

    Use typedef member from a template class outside of the class as return type for member function

  18. 18

    How do I typedef a method pointer with the C++11 using syntax?

  19. 19

    How do I return a function pointer as const?

  20. 20

    how to pass pointer to member function of a template class?

  21. 21

    how do I specialize a bound template friend function to a template class?

  22. 22

    Template function pointer of template class - C++

  23. 23

    C++ typedef function definition as a class member to use later for function pointer?

  24. 24

    Typedef Template Class Pointer in*.cpp file

  25. 25

    C++ How can I call a template function with a template class?

  26. 26

    Typedef pointer in a Class Template

  27. 27

    How do I return a function pointer as const?

  28. 28

    C++ function template: Must use & for argument type and return type?

  29. 29

    How do I use typedef with class initializer parameters in C++?

HotTag

Archive