Skip to main content
Tuoman
Senior II
March 4, 2020
Solved

Cast custom container to Drawable*

  • March 4, 2020
  • 1 reply
  • 861 views

I want to use container as Drawable*, so I can use methods like moveTo() etc. to move the container around.

I have my container in View, which is selectorboxContainer, which inherits from selectorboxContainerBase, which inherits from touchgfx::Container, which inheirts from Drawable.

I can get Drawable* to this object using this method:

Drawable* selectorbox = getFirstChild();

But I cannot do it like this:

Drawable* selectorbox = (Drawable*) selectorBox1;

I get error:

 error: invalid cast from type 'selectorboxContainer' to type 'touchgfx::Drawable*'

Why getFirstChild() can cast my container to Drawable*, but I cannot do it by casting?

I don't want to use getFirstChild(), because it blindly picks Drawable based on order, instead of the drawable name. If someone reorders drawables, it will break the application.

This topic has been closed for replies.
Best answer by PBull

Hi,

this should work:

Drawable* selectorbox = (Drawable*)&selectorBox1;

but there is no need for a cast, you can move the container directly (as you mentioned, the custom container is derived from Drawable)

selectorBox1.moveTo(20,20);

Best regards,

Peter

1 reply

PBull
PBullBest answer
Associate II
March 4, 2020

Hi,

this should work:

Drawable* selectorbox = (Drawable*)&selectorBox1;

but there is no need for a cast, you can move the container directly (as you mentioned, the custom container is derived from Drawable)

selectorBox1.moveTo(20,20);

Best regards,

Peter