Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7443413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:19:34+00:00 2026-05-29T11:19:34+00:00

I am trying to learn how to call this write_data(…) function from the funmain()

  • 0

I am trying to learn how to call this write_data(…) function from the funmain() function in the class as shown in the code bellow. (I know this program works if I just list these two functions without putting it inside a class).

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data) line gives me error and wouldn’t let me call the write_data(…) function. Can you please correct my code and tell me how I can achieve this. Any help would be greatly appreciated. Thanks.

error C3867: 'go_website::write_data': function call missing argument list; use '&go_website::write_data' to create a pointer to member

//Microsoft Visual Studio 10 in C++
#define CURL_STATICLIB
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <iostream>
#include <curl/easy.h>
#include <string>
using namespace std;

extern "C" typedef size_t curl_write_callback(void *ptr, size_t size, size_t nmemb, FILE *stream);
class go_website
{
public:
static curl_write_callback write_data;

void funmain()
{
    CURL *curl;
    FILE *fp;
    CURLcode res;
    char *url = "http://www.shorturl.com/";
    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, &write_data); 
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
    }
}};

extern "C" 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;
}

int main()
{
   go_website a;
   a.funmain();
   return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:19:35+00:00Added an answer on May 29, 2026 at 11:19 am

    These two lines won’t work:

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fp);
    

    The second is the easiest to fix: fp is a file pointer, not a function, you’re setting the wrong attribute, I guess you want CURLOPT_WRITEDATA.

    For the callback function, you need a function pointer. The name of an ordinary function automatically decays to its address, although using the address-of operator (&functionname) is cleaner.

    Class member functions do not automatically decay. In fact, a non-static class member function is totally incompatible with a normal function pointer, since there’s no way to handle this. Luckily you don’t need a non-static member function, since no non-static members are used inside the callback.


    Make the callback function static andextern "C":

    extern "C" typedef size_t curl_write_callback(void *ptr, size_t size, size_t nmemb, FILE *stream);
    
    class go_website
    {
    public:
        static curl_write_callback write_data;
    
        // ...
    };
    
    extern "C" size_t go_website::write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
    {
       size_t written;
       written = fwrite(ptr, size, nmemb, stream);
       return written;
    }
    

    and then take its address, using the address-of operator and fully-qualified function name:

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &go_website::write_data);
    

    This part was even explained in the error message. But it didn’t tell you that you needed static or extern "C", this is the problem with variable argument lists, they aren’t typesafe.

    After reading the Standard (section 7.5 [dcl.link], and especially paragraph 4 and its examples), this isn’t allowed. The member function still has C++ language linkage, for both its name (not important) and its type (this is the deal-breaker).

    You have to use a global function for the callback:

    extern "C" 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;
    }
    

    and then pass a pointer to it:

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to learn OOP and I've made this class class boo{ function boo(&another_class,
I know this is a basic PHP question, and I'm trying to learn the
I'm trying to learn Erlang, coming from a C++/Java background. This forces me to
I'm trying to learn to call SharePoint Web Services from an external C# client.
Trying to learn a bit about PDO and is going through this tutorial .
Trying to learn MVP pattern with C#... Does anyone know of any particularly good
I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to
I'm trying to learn C++ so forgive me if this question demonstrates a lack
I am trying to learn inline assembly programming in Delphi, and to this end
I'm trying to write some code in java to learn more about coding with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.