Search the Community
Showing results for tags 'array passing'.
-
[SOLVED] Passing array to member function causes error, but to global function is OK
ed.koffeman posted a topic in C++ Programming
I can pass an array to a global C++ function, from the example given in the topic: int arrayOfInts[] = ( 0, 1 ); int i = 0; my_array_vector_set( arrayOfInts, i, string(i) ); no problem. However, doing essentially the same call, but to a method of a C++ class gives an error: ArrayPassingClass passingTest = new ArrayPassingClass(); passingTest.my_array_vector_set2( arrayOfInts, i, string(i) ); gives "Interpreter::parse_expression(): arrays can't be used in expressions" In C++: class ArrayPassingClass { public: // 2.1. Declare a class constructor that will be exported into Unigine script. ArrayPassingClass() { } ~ArrayPassingClass() { } void my_array_vector_set2(const Variable &id,int index,const Variable &v) { ArrayVector vector = ArrayVector::get( Interpreter::get(), id); vector.set(index,v); } }; void my_array_vector_set(const Variable &id,int index,const Variable &v) { ArrayVector vector = ArrayVector::get( Interpreter::get(), id); vector.set(index,v); } ... ExternClass<ArrayPassingClass> *my_arrayPassingClass = MakeExternClass<ArrayPassingClass>(); my_arrayPassingClass->addConstructor(); my_arrayPassingClass->addFunction( "my_array_vector_set2", &ArrayPassingClass::my_array_vector_set2 ); Interpreter::addExternClass("ArrayPassingClass", my_arrayPassingClass ); Interpreter::addExternFunction("my_array_vector_set",MakeExternFunction(&my_array_vector_set,"[]")); Do things need to be done differently when calling a member function? or, is this a bug? If so, does it have a work-around?