0

I'm familiar with C and pointers, but this part is new to me. Take a look at this method declaration in godot-headers:

godot_class_constructor (*godot_get_class_constructor)(const char *p_classname);

There is a * applied to the method name. Or at least, I think this is a method? There are a lot of method declarations like this, here I just picked the one I'm trying to use. In particular, I noticed that the name of the method with the asterisk (first set of parenthesis) is separate from the list of parameters in the method (second set of parenthesis). I don't know what this means. Method pointer? Dereference method? For context, here is how godot_class_constructor is defined:

typedef godot_object *(*godot_class_constructor)();

The C source doesn't include an example use case for this, however, here is an example usage from the Godot C++ bindings:

static godot_class_constructor base_constructor = godot::api->godot_get_class_constructor(T::___get_godot_class_name());
godot_object *base_obj = base_constructor();

I have not been able to replicate the above in C without crashing, but here is my failed attempt:

godot_class_constructor directory_constructor = api->godot_get_class_constructor("Directory");
godot_object *directory = directory_constructor();
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Aaron Franke
  • 3,268
  • 4
  • 31
  • 51

0 Answers0