問(wèn)題描述
class Filter{
private:
string contents;
bool Server(void);
public:
void handle(void *, size_t, size_t, void *);
};
我有一個(gè)這樣的類標(biāo)題.我想在函數(shù) Server 中調(diào)用 curl WRITEFUNCTION ,該函數(shù)將使用句柄寫(xiě)入字符串內(nèi)容.雖然它一直給我錯(cuò)誤
i have a class header like this. i want to call curl WRITEFUNCTION inside the function Server which would use handle to write to the string contents. although it keeps giveng me the error
error: invalid use of member (did you forget the ‘&’ ?)
錯(cuò)誤指向的那一行是 CURLOPT_WRITEFUNCTION.... 我的 curl 請(qǐng)求看起來(lái)像這樣...
the line pointed by error is that of CURLOPT_WRITEFUNCTION.... My curl request looks something like this...
curl_easy_setopt(curl,CURLOPT_URL, address.c_str());
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,handle);
curl_easy_perform(curl);
這意味著它無(wú)法訪問(wèn) handle()..我該如何糾正?
that means its unable to access the handle().. how can i rectify this?
推薦答案
string temp;
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,handle);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&temp);
size_t Filter::handle(void *ptr, size_t size, size_t nmemb, string stream)
{
string temp(static_cast<const char*>(ptr), size * nmemb);
stream = temp;
return size*nmemb;
}
這就是我讓它工作的方式..這會(huì)將網(wǎng)站保存到名為 temp 的字符串中.
thats how i got it to work.. this will save the website to the string named temp.
這篇關(guān)于curl WRITEFUNCTION 和類的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!