Question

    HttpRequest* request = new HttpRequest();
    request->setUrl("http://just-make-this-request-failed.com");
    request->setRequestType(HttpRequest::Type::GET);
    request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted));

This code is from the NetworkTest of cocos2d-x 3.0. I don't understand why I should pass Layer* to setResponseCallback? What if I want to send/get request/response without creating a single layer? Why shouldn't I be able to do that?

Was it helpful?

Solution

Selector in obj-c is just the name of the method so in order to call it you need a reference to the object as well. The code calls it "httpresponse_selector" and cocos2d-x is reportedly modelled after obj-c so might be it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top