我已经研究了好几个小时了。我对 C++ 很陌生,到目前为止我还没有找到任何解决方案。
我正在尝试在我的表单应用程序中创建一个 cURL 文件下载器,但我收到了这个该死的错误:
Error 50 error C3374: can't take address of 'EmperorAntiVirusInstaller::FileDownloader::write_data' unless creating delegate instance c:\users\bailey\documents\visual studio 2010\projects\emperor antivirus installer\emperor antivirus installer\FileDownloader.h 97
代码如下:
private:
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
System::Void beginDownload(void) {
CURL *curl;
FILE *fp;
CURLcode res;
char *url = "http://localhost/aaa.txt";
char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
curl = curl_easy_init();
if(curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &FileDownloader::write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
}
此外,表单的名称是 FileDownloader。
错误行是:
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &FileDownloader::write_data);
我正在寻找关于如何解决此问题的很好解释且简单的答案。:/