title: C++,Strategy to use base class pointer storing subclasses and use the derived classes' method
body: <p>The base class is the base of every classes in the program, which provides the x_pos and y_pos.
  <br>
  <del>Animal</del>(deleted for clearity) and Person are direct child classes of Base. <br>
  Different people and animals may be created as sub-classes of Animal and Person<br>
  In my example, I created Wang class. <br></p>
  
  <p>I have the following classes. <br></p>
  
  <pre><code>#include &lt;iostream&gt;
  class Base{ 
  protected:    
      int x_pos;
      int y_pos;
  public:
      Base(int x,int y): x_pos(x), y_pos(y){};
      virtual ~Base(){};
      int getX(){return x_pos;};
      int getY(){return y_pos;};
  };
  
  class Person : public Base{
  protected:
      char sex;
  public:
      Person(int x,int y,char sex):Base(x,y), sex(sex){};
      virtual ~Person(){};
      char getSex(){return sex;};
      virtual void haveFun() = 0;
  };
  
  class Wang : public Person{
  public:
      Wang(int x,int y,char a): Person(x,y,a){};
      ~Wang(){};
      void haveFun(){ std::cout &lt;&lt; "Wang is coding" &lt;&lt; std::endl;};
  };
  </code></pre>
  
  <p>The question is that, for some reason, I must have a Base pointer to store the person or the animal.(For example, a floor has a "Base" that steps on it)<br></p>
  
  <pre><code>class Floor{
      Base *bs;
  public:
      void haveFun(){ 
        // bs-&gt;Wang::havefun();
        // I want to achieve this goal
      }
  }
  </code></pre>
  
  <p>How can I get access to the methods on Person/Animal and Wang level without down casting<br>
  Is there any strategy that I can apply here?<br>
  (I kind of think vistor's pattern may be applied here but I cant figure out how)</p>