title: C++: Cast parent class to child class
body: <p>I'm fairly new to C++ and this is the problem I have:
   I have two classes, <code>Client</code> and <code>Host</code>. And when everything is loaded you have the option to press two buttons, if you press button 1 <code>Client</code> is loaded and if you press button 2 <code>Host</code> is loaded.</p>
  
  <p>Now both <code>Client</code> and <code>Host</code> are fairly big classes, and I don't want to put them both into the memory. So my idea was creating a <code>Base</code> class, and then both <code>Client</code> and <code>Host</code> should extend the base class, and then the only thing I had to do was this:</p>
  
  <pre><code>Base connection;
  
  //If button 1 is pressed:
  connection = Client();
  
  //If button 2 is pressed:
  connection = Host();
  </code></pre>
  
  <p>Well this sounded almost too good to be true, and when I tried it I got no errors. Now comes the problem, <code>Base</code> has a function called <code>A</code>, and <code>Client</code> has a function called <code>B</code>. So the function <code>B</code> is unique to the class <code>Client</code>.</p>
  
  <p>When I try to call function <code>B</code> I get this error: <code>'class Base' has no member named 'B'</code>. How can I let C++ know that I am talking to class <code>Client</code> or <code>Host</code> instead of <code>Base</code>? I am also open for a whole new approach to this problem. Maybe it's just an error in my thinking process.</p>
  
  <p>Thanks in advance!</p>