question

Mischa Spelt avatar image
0 Likes"
Mischa Spelt asked Mischa Spelt answered

Binding bracket operator

Hi @jordan.johnson,

Could you help me bind a bracket operator in my custom class? By looking at the macro definition, I figured that something like this should work:

void MyObjectArray::bindInterface() const
{
  bindTypedProperty( length, int, &MyObjectArray::GetLength, nullptr );
  // ...
  bindBracketOperator( MyObject, MyObjectArray, int );
}
int MyObjectArray::GetLength() const
{
  return this->length;
}
MyObject MyObjectArray::operator[]( int index ) const
{
  return this->objects[index];
}

but when I try to use it in FlexSim I get

Could not resolve correct operator for [] operation. Left side type is MyObjectArray, right type is int

and also the [...] does not show up in code completion.
Is there a bug or did I misinterpret the arguments to bindBracketOperator?

Thanks!

FlexSim 17.1.2
module sdkdot syntaxbracket operator
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mischa Spelt avatar image Mischa Spelt commented ·

As a side note: I wanted to return by value from operator[], is that allowed as long as MyObject is copyable or does FlexSim always need a reference?

0 Likes 0 ·

1 Answer

Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered

Never mind, I figured it out. The code is correct, I just forgot to

bindClass( MyObject )

so probably FlexSim was confused about that.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.