1
    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?

Narek
  • 38,779
  • 79
  • 233
  • 389

1 Answers1

1

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.

antont
  • 2,676
  • 1
  • 19
  • 21
  • Really, this could be the answer! Thank you! :) – Narek May 12 '14 at 23:26
  • 1
    The answer there says: "void (CCObject::*)(CCObject*) is a method pointer type (one type of pointer to member), not an ordinary function pointer. It's a pointer that can point to an instance method of the CCObject class that takes a parameter of CCObject* type." .. "The typedef simply defines SEL_MenuHandler to be a synonym for that method pointer type." . That SEL_* is a selector i think. http://stackoverflow.com/questions/18265300/c-understanding-cocos2d-x-use-of-function-pointers – antont May 12 '14 at 23:31