My goal is to build a C++ class to abstract away several POST methods. I reckon I want to have one instance of a CURL object for the entire class, which all the methods share.
Here's my test setup which works fine
Header file
#pragma once
#include <curl/curl.h>
class RPC
{
public:
RPC();
};
cpp file
RPC::RPC()
{
CURL* m_curl;
m_curl = curl_easy_init();
// curl_easy_setopt() and curl_easy_perform()
curl_easy_cleanup(m_curl);
}
This code builds and runs and produces the expected output. The problem is when I try to make m_curl
a private member of the RPC
class. The RPC
class will have multiple methods calling curl_easy_perform()
, and I do not want to have to call curl_easy_init()
and curl_easy_cleanup
every time. I want to call them once in the constructor and destructor, respectively.
This is what I want
Header file
#pragma once
#include <curl/curl.h>
class RPC
{
public:
RPC();
~RPC();
void someMethod();
private:
CURL* m_curl;
};
cpp file
RPC::RPC()
{
m_curl = curl_easy_init();
}
RPC::~RPC()
{
curl_easy_cleanup(m_curl);
}
void RPC::someMethod()
{
// curl_easy_setopt() and curl_easy_perform()
}
The problem is with this line in the header file:
CURL* m_curl;
I get the following 3 build errors:
error C2143: syntax error: missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
I have also tried calling curl_easy_init() in an initializer list, like this:
RPC::RPC() : m_curl(curl_easy_init())
But that produces the same build errors.
Any help is appreciated! :)
edit: I did include curl in the header.
#pragma once
#include <curl/curl.h>