Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Karvalho | |
Old Version | Published before Godot 3 was released. |
Regarding new modules in C++, after I read this, I understood I should instantiate new classes using memnew()
When I instantiated a Dictionary, for example, like this:
Dictionary dict = memnew(Dictionary);
It worked! Great. But when I tried the same with Vector2:
Vector2 v = memnew(Vector(1, 1)); // compiler error
Vector2* v = memnew(Vector(1, 1)); // returns a boolean???
It didn’t work. Instead, I managed to instantiate Vector2 like this:
Vector2 v = Vector2(1, 1);
I suppose this is wrong, since it could lead to potential memory leaks? When and how should I use memnew in this case?