cancel
Showing results for 
Search instead for 
Did you mean: 

Cast custom container to Drawable*

Tuoman
Senior II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PBull
Associate III

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

View solution in original post

1 REPLY 1
PBull
Associate III

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