title: Inheritance in Arduino Code
body: <p>I'm writing some Arduino code and attempting to use inheritance in some classes. I have a class "Actor" (my base class) and a class "Marble" (which inherits from Actor). Here are the header files:</p>
  
  <p>Actor.h:</p>
  
  <pre><code>#ifndef Actor_h
  #define Actor_h
  
  #include "Arduino.h"
  
  class Actor
  {
    public:
      Actor();
      void speak();
    private:
  };
  #endif
  </code></pre>
  
  <p>Marble.h:</p>
  
  <pre><code>#ifndef Marble_h
  #define Marble_h
  
  #include "Arduino.h"
  #include "Actor.h"
  
  class Marble : public Actor {
    public:
      Marble();
      virtual void speak();    
    private:
  };
  #endif
  </code></pre>
  
  <p>Actor.cpp:</p>
  
  <pre><code>#include "Arduino.h"
  #include "Actor.h"
  
  Actor::Actor()
  {
  }
  
  void Actor::speak() {
    Serial.println("Actor"); 
  }
  </code></pre>
  
  <p>Marble.cpp:</p>
  
  <pre><code>#include "Arduino.h"
  #include "Marble.h"
  
  void Marble::speak() {
    Serial.println("Marble"); 
  }
  </code></pre>
  
  <p>And finally, in the loop function I do:</p>
  
  <pre><code>void loop() {
    Marble marble;
    Actor children[2];
    children[0] = marble;
  
    children[0].speak();
  </code></pre>
  
  <p>Which results in "Actor" being printed.</p>
  
  <p>I discovered this nice link which seems similar to my issue, but the resolution does not seem to work for me:
  <a href="http://arduino.cc/forum/index.php?topic=41884.0" rel="nofollow">http://arduino.cc/forum/index.php?topic=41884.0</a></p>
  
  <p>So. It seems like when I create my array of "Actors" and try and stick Marble in there it gets cast to an Actor, or something like that. Problem is, I'll have a few different characters that will all inherit from "Actor" and I'd like an array of them to iterate over and call overridden methods on them.</p>
  
  <p>So, perhaps the problem is how I'm approaching this problem, or maybe there's some syntax errors? I don't know!</p>
  
  <p>Thanks for your help,
  Kevin</p>