I am trying to to implement in C++ basic math operators (+, *, +=, ...) for a custom class used to handle specific data about my game.
I already managed to create that custom class in the modules folder, and bind a few basic methods. This custom class is accessible in the engine after recompiling it, and the binded methods as well. However, I found no documentation on operators overloading for the godot engine, nor found any example online.
Is it possible? And if so, is there an exemple somewhere?
If not, I guess I could add my custom class directly in the /core folder?
Here is what I have tried
MyResource.h :
class MyResource : public Reference {
GDCLASS(MyResource, Reference);
public :
float gold;
...
void operator+=(const MyResource &obj);
};
void MyResource::operator+=(const MyResource &obj) {
this->gold += obj.gold;
}
It compiles fine, but when I try to use the operator "+=" in the editor, I get the following error : "Invalid operands 'Object' and 'Object' in operator '+'".
I have not used "ClassDB::bind_method" for the += operator. Should I?
Thank you in advance for your help