C++ cannot pass objects of non-POD type

ash-breeze picture ash-breeze · May 4, 2012 · Viewed 28.5k times · Source

This is my code:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <curl/curl.h>
using namespace std;
int main ()
{
    ifstream llfile;
    llfile.open("C:/log.txt");

    if(!llfile.is_open()){
        exit(EXIT_FAILURE);
    }

    string word;
    llfile >> word;
    llfile.close();
    string url = "http://example/auth.php?ll=" + word;

    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, url);
        res = curl_easy_perform(curl);

        /* always cleanup */
        curl_easy_cleanup(curl);
    }
    return 0;
}

This is my error when compiling:

main.cpp|29|warning: cannot pass objects of non-POD type 'struct std::string' through '...'; call will abort at runtime

Answer

The problem you have is that variable argument functions do not work on non-POD types, including std::string. That is a limiation of the system and cannot be modified. What you can, on the other hand, is change your code to pass a POD type (in particular a pointer to a nul terminated character array):

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());