I'm using Casablanca C++ Rest SDK for http connections. Here is a basic piece of code that makes a http request.
Copied from Casablanca documentation:
// Creates an HTTP request and prints the length of the response stream.
pplx::task<void> HTTPStreamingAsync()
{
http_client client(L"http://www.google.com");
// Make the request and asynchronously process the response.
return client.request(methods::GET).then([](http_response response)
{
// Response received, do whatever here.
});
}
This will do an asynchronous request and do a callback when done. I need to make my own class that uses these codes and I want to wrap it to my own callback.
For simplicity, assume that I want to make a class that has method which print html code of google.com.
So I expected something like this:
MyClass myObject;
myObject.getGoogleHTML([](std::string htmlString)
{
std::cout << htmlString;
});
I searched and read related articles like:
- C++ class member callback simple examples
- C++11 styled callbacks?
- Friday Q&A 2011-06-03: Objective-C Blocks vs. C++0x Lambdas: Fight!
But I'm still a bit confused as I get used with completion block
in Objective-C
. How can I construct such a class that wraps callback?