title: Void pointer to object pointer
body: <p>I'm developing a GUI for a mbed microcontroller in C++ and I have a few problems.</p>
  
  <p>The situation is:
  Different widget classes (button, slider...) with a widget virtual parent function. Then a virtual function layout with also classes like (gridLayout, ...). The layout has functions like layout.add(*widget) to add the widget pointers to a vector.
  Then I have a controller function that handle the touch events and uses the current active layout to check what the correct widget is in the layout at the x,y coordinates of the touch.</p>
  
  <p>Now I want to add a pointer pointed to a layout in the widget class so the controller class can possible change the activeLayout if this is required. There is also a function pointer so the controller can run a certain function when a widget is used.</p>
  
  <p>Now the problem: I would like to do something like this:</p>
  
  <pre><code>Button::Button(char* text_, int color_, void *function_, Layout *layout_): text(text_), color(color_), function(function_), layout(layout_){}
  </code></pre>
  
  <p>But then I need to include the layout class, and the layout class already includes the widget class --> error! What is the easiest way to do this? I already tried void* pointers and then a static cast to Layout but that didn't work.</p>
  
  <p>I also need to include a TFT class in every widget and layout, what would be the easiest way to do that? Now I just have a Display.h with in it:</p>
  
  <pre><code>#ifndef DISPLAY_H
  #define DISPLAY_H
  
  static SPI_TFT Screen(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"Screen");
  
  #endif
  </code></pre>
  
  <p>But I don't really think this is the correct way to do something like this.</p>
  
  <p>Thank you very much for your help!</p>