I'm trying to write a template callback function for libcurl. However, when using a pointer to an instance of the template function, VC++ 2008 and 2010 keep giving me this error:
template-callback.cpp(27) : error C2664: 'curl_easy_setopt' : cannot convert parameter 3 from 'size_t (__cdecl *)(void *,size_t,size_t,void *)' to '...' Context does not allow for disambiguation of overloaded function
But GCC (4.5.1) compiles the code without a problem. This is a trimmed version of the code:
#include <string>
template<typename String>
size_t callback(
void* ptr
, size_t size
, size_t nmemb
, void* userdata
)
{
//String* str = static_cast<String*>(userdata);
size_t len = size*nmemb;
//str->append(static_cast<char const*>(ptr), len);
return len;
}
typedef size_t (*write_callback)(void*, size_t, size_t, void*);
struct CURL;
enum CURLOption { none };
void curl_easy_setopt(CURL*, CURLOption, ...);
void f()
{
CURL* curl = NULL;
CURLOption option = none;
// This gives an error
curl_easy_setopt(curl, option, &callback<std::string>);
// This doesn't
write_callback cb = &callback<std::string>;
curl_easy_setopt(curl, option, cb);
}
Is this a bug in VC++ or am I doing something wrong?