pass "pointer to pointer" to a template function

A.3dhgi

I have a funtion which allocates memory to a pointer as following:

   void initializeImageBuffer(unsigned char **image, int w, int h)
   {
        if (*image != NULL)
            delete[] *image;
        *image = new unsigned char[w * h];
   }

now I want to generalize the argument type (unsigned char/int/double) using function template. Thats what I did:

 template<typename T, int, int>
 void initializeImageBuffer(T **image, int w, int h)
   {
        if (*image != NULL)
            delete[] *image;
        *image = new T[w * h];
   }

But there is an error using the function like:

    unsigned char* image;
    initializeImageBuffer(&image, 200, 200);

"There is no instance of overloading function with these argument types. The Arguments types are (unsigned char**, int, int)."

Quentin
template<typename T, int, int>

Here you declare that your template has three parameters, the type T and two unnamed ints. Since there is no way to deduce the value of the ints at the call site, you would need to provide them explicitly, along with T since you can only provide template arguments from left to right:

initializeImageBuffer<unsigned char, 42, 42>(&image, 200, 200);

However, what you most probably want is just to drop these ints, they have absolutely no use here.

template<typename T>
void initializeImageBuffer(T **image, int w, int h)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Function with input of pointer to pointer to

From Dev

template overloading plus pointer to pointer

From Dev

template overloading plus pointer to pointer

From Dev

Why can't I pass the address of a pointer to a fixed size array into a function expecting a pointer to a pointer in C?

From Dev

Pointer to pointer parameter in Swift function

From Dev

Pointer to Pointer to Void Function Parameter

From Dev

PInvoke function with pointer to pointer parameter

From Dev

c++ pointer to pointer and call function that receive pointer to pointer

From Dev

The logic behind pass by pointer to pointer in C

From Dev

Conversion between a void pointer and a pointer to function pointer

From Dev

passing a pointer to a pointer in c function by value

From Dev

Why is a pointer to a pointer to a function 8 byte?

From Dev

changing the value of pointer to a pointer in a c function

From Dev

Can you return a type of pointer to pointer in a function?

From Dev

Can I pass a pointer to a pointer, allocate memory, then pass it back?

From Dev

When to pass a pointer to pointer as argument to functions in C++?

From Dev

Why do I have to pass a pointer to a pointer in this case

From Dev

Delete a pointer with a pointer to that pointer

From Dev

OpenCL:Why Pointer to a pointer cannot be passed as an argument to a kernel function?

From Dev

C Pointers, Casting, Pointer to a pointer to a function, help understanding complex pointers

From Dev

How to create a Red/System binding to a function that takes a pointer to a pointer?

From Dev

Pointer to character passed to function. Why not pointer to pointer?

From Dev

Passing String Address As Parameter To Pointer To Pointer To Char Function

From Dev

C malloc of pointer to pointer inside function not giving correct size

From Dev

C malloc of pointer to pointer inside function not giving correct size

From Dev

Why does function taking char pointer pointer not work?

From Dev

Can we return value which is non pointer to the pointer function

From Dev

How to pass a function to a Meteor template?

From Dev

How to pass a variadic template function?

Related Related

  1. 1

    Function with input of pointer to pointer to

  2. 2

    template overloading plus pointer to pointer

  3. 3

    template overloading plus pointer to pointer

  4. 4

    Why can't I pass the address of a pointer to a fixed size array into a function expecting a pointer to a pointer in C?

  5. 5

    Pointer to pointer parameter in Swift function

  6. 6

    Pointer to Pointer to Void Function Parameter

  7. 7

    PInvoke function with pointer to pointer parameter

  8. 8

    c++ pointer to pointer and call function that receive pointer to pointer

  9. 9

    The logic behind pass by pointer to pointer in C

  10. 10

    Conversion between a void pointer and a pointer to function pointer

  11. 11

    passing a pointer to a pointer in c function by value

  12. 12

    Why is a pointer to a pointer to a function 8 byte?

  13. 13

    changing the value of pointer to a pointer in a c function

  14. 14

    Can you return a type of pointer to pointer in a function?

  15. 15

    Can I pass a pointer to a pointer, allocate memory, then pass it back?

  16. 16

    When to pass a pointer to pointer as argument to functions in C++?

  17. 17

    Why do I have to pass a pointer to a pointer in this case

  18. 18

    Delete a pointer with a pointer to that pointer

  19. 19

    OpenCL:Why Pointer to a pointer cannot be passed as an argument to a kernel function?

  20. 20

    C Pointers, Casting, Pointer to a pointer to a function, help understanding complex pointers

  21. 21

    How to create a Red/System binding to a function that takes a pointer to a pointer?

  22. 22

    Pointer to character passed to function. Why not pointer to pointer?

  23. 23

    Passing String Address As Parameter To Pointer To Pointer To Char Function

  24. 24

    C malloc of pointer to pointer inside function not giving correct size

  25. 25

    C malloc of pointer to pointer inside function not giving correct size

  26. 26

    Why does function taking char pointer pointer not work?

  27. 27

    Can we return value which is non pointer to the pointer function

  28. 28

    How to pass a function to a Meteor template?

  29. 29

    How to pass a variadic template function?

HotTag

Archive