Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | curious_orange | |
Old Version | Published before Godot 3 was released. |
Hi, I’m new to C++ module development. Following the documentation and some examples, I tried a simple test module where there are two classes. Here a “class 2” member function (mul) is to have “class 1” type arguments. Declared in header file as below:
class class_1 : public Reference {
OBJ_TYPE(class_1, Reference);
...
and then
class class_2 : public Reference {
OBJ_TYPE(class_2, Reference);
public:
class_2();
virtual ~class_2();
float mul(class_1, class_1);
...
But I get “no known conversion for argument 1 from ‘class_1’…” errors during compilation, at variant.h. The below is the initial part of error message, as it is repeated for all variant types.
core/method_bind.inc:1296:87: required from 'Variant::Type MethodBind2R<R, P1,
P2>::_gen_argument_type(int) const [with R = class_1; P1 = class_1; P2 = class_
1]'
modules\SimpleTest\mtest.cpp:52:1: required from here
core/variant.h:177:19: error: no matching function for call to 'Variant::Variant
(class_1&)'
Variant v(t.type);
^
In file included from core/object.h:33:0,
from core/reference.h:32,
from modules\SimpleTest\mtest.h:4,
from modules\SimpleTest\mtest.cpp:1:
core/variant.h:439:17: note: candidate: Variant::Variant()
_FORCE_INLINE_ Variant() { type=NIL; }
^
core/variant.h:439:17: note: candidate expects 0 arguments, 1 provided
core/variant.h:438:2: note: candidate: Variant::Variant(const Variant&)
Variant(const Variant& p_variant);
^
core/variant.h:438:2: note: no known conversion for argument 1 from 'class_1'
to 'const Variant&'
In file included from core/object.h:33:0,
from core/reference.h:32,
from modules\SimpleTest\mtest.h:4,
from modules\SimpleTest\mtest.cpp:1:
core/variant.h:325:2: note: candidate: Variant::Variant(const IP_Address&)
Variant(const IP_Address& p_address);
^
core/variant.h:325:2: note: no known conversion for argument 1 from 'class_1'
to 'const IP_Address&'
As I understand, function arguments are only compared against existing variant types. How can one have custom types in a module, be recognized as valid arguments? Is this a binding or a compilation order issue? I tried various arrangements of source files (common/separate headers etc.) assuming the latter, with same outcome. Help would be appreciated.
Note: Using minGW for compilation (compiles Godot fine without this test module).