   function pointer to template function (c++)
  Consider the following code:template<class oiter_t>size_t curl_write(void *ptr, size_t size, size_t nmemb, void *data) {    oiter_t oiter = *static_cast<oiter_t*> (data);    const char* ch_ptr = static_cast<const char*> (ptr);    std::copy(ch_ptr, ch_ptr + size * nmemb, oiter);    return nmemb;}template<class oiter_t>void download(std::string url, oiter_t oiter) {    ...    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_write<oiter_t>);    ...}where oiter is an output iterator. As you can see I have to set a callback function curl_write at some point in the download function. That line produces a compilation error:error: address of overloaded function with no contextual type informationI have solved the problem by wrapping both function in a template<class oiter_t> class, but I would like to know whether it is possible to get a function pointer to curl_write<oiter_t>.   
  Strange. Have you tried specifying the type of the function you're passing using a cast? typedef void (*CURL_WRITE)(void *ptr, size_t size, size_t nmemb, void *data);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, (CURL_WRITE) &curl_write<oiter_t>);;  It produces the same error. I think casting works only if the template argument appears somewhere in the function declaration.[Edited by - Kambiz on December 29, 2008 6:39:29 AM];  What happens when you cast to void as I suspect the libcurl library uses a void* due to being a C library.curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, (void*)(&curl_write<oiter_t>) );Casting a function pointer to a void* is not implicit in C++ as it is not a valid cast.Also which compiler and version are you using? I suspect g++   ;Quote:Original post by CmpDevWhat happens when you cast to void as I suspect the libcurl library uses a void* due to being a C library.*** Source Snippet Removed ***Casting a function pointer to a void* is not implicit in C++ as it is not a valid cast.Also which compiler and version are you using? I suspect g++Exactly the same error message.   ;  There is a proposed solution posted on the c++ mailing list. I will post it here for completeness sake, it involves a function returning the parameter.template<typename T>T foo(T t){return t;}curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, foo(&curl_write<oiter_t>));Does this work?   ;  Solved:Casting works, the problem was the typedef:typedef void (*CURL_WRITE)(void *ptr, size_t size, size_t nmemb, void *data);void should be size_t:typedef size_t (*CURL_WRITE)(void *ptr, size_t size, size_t nmemb, void *data);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,  (CURL_WRITE)(&curl_write<oiter_t>));compiles fine.the solution suggested by CmpDev works also. Although, I would like to know why it works. Thanks!   