title: C++ virtual function resolution issue
body: <p>The program throws an error at this function call resolution:  </p>
  
  <pre><code>for(vector&lt;Catalog*&gt;::iterator i=m_subDeptList.begin(); i!=m_subDeptList.end();  ++i)
           (*i)-&gt;displayDiscription();
  </code></pre>
  
  <p>The Error:</p>
  
  <pre><code>test.cpp: In member function ‘void Department::displayDiscription()’:
  test.cpp:73:14: error: ‘class Catalog’ has no member named ‘displayDiscription’
      (*i)-&gt;displayDiscription();
  </code></pre>
  
  <p>But there are no issues with the following call resolutions:</p>
  
  <pre><code>for(vector&lt;Product*&gt;::iterator i=m_products.begin(); i!=m_products.end();  ++i)
          (*i)-&gt;displayDiscription();
  for(vector&lt;Catalog*&gt;::iterator i=m_subDeptList.begin() ; i!=m_subDeptList.end();  ++i)
          (*i)-&gt;addDiscount(discount);
  for(vector&lt;Product*&gt;::iterator  i=m_products.begin(); i!=m_products.end();  ++i)
          (*i)-&gt;addDiscount(discount);
  </code></pre>
  
  <p>Can anybody explain this? </p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  class Catalog
  {
      string m_name;
  public:
      Catalog(const string &amp;name):m_name(name){}
      //virtual ~Catalog(){}
      const string&amp; getName()
      {
          return m_name;
      }
  
      virtual bool addDiscount(unsigned int discount)=0;
      virtual void displayDescription()=0;      
  };
  class Product:public Catalog
  {
      unsigned short m_discount; // discount in %
      long double m_price;
  public:
      Product(const string&amp; productName, const long double &amp;price):Catalog(productName),m_price(price){}
      void displayDiscription()
      {
          cout&lt;&lt;getName()&lt;&lt;"price: "&lt;&lt;getPrice()&lt;&lt;endl;
      }    
      bool addDiscount(const unsigned int discount)
      {
          if( discount &gt; 100 || discount &lt; 0)
              return false;
          m_discount+=discount;
          return true;
      }
      long double getPrice()
      {
          return m_price;
      }
  
  };
  class Department:public Catalog
  {
      vector&lt;Product*&gt; m_products;
      vector&lt;Catalog*&gt; m_subDeptList;
      unsigned int discountApplied;
  public:
      Department(const string &amp;name):Catalog(name){}
  
      bool addDiscount(unsigned int discount) // add discount to all products in this dept/subDept
      {
          if( discount &gt; 100 || discount &lt; 0)
              return false;
  
          for(vector&lt;Catalog*&gt;::iterator i=m_subDeptList.begin() ; i!=m_subDeptList.end();  ++i)
              (*i)-&gt;addDiscount(discount);
          for(vector&lt;Product*&gt;::iterator  i=m_products.begin(); i!=m_products.end();  ++i)
              (*i)-&gt;addDiscount(discount);
          discountApplied+=discount;
          return true;
      }    
  
      void displayDiscription()
      {
  
          cout&lt;&lt;getName()&lt;&lt;endl;
  
          if(!m_subDeptList.empty() )
          for(vector&lt;Catalog*&gt;::iterator i=m_subDeptList.begin(); i!=m_subDeptList.end();  ++i)
               (*i)-&gt;displayDiscription();
  
          if(!m_products.empty() )
              for(vector&lt;Product*&gt;::iterator i=m_products.begin(); i!=m_products.end();  ++i)
              (*i)-&gt;displayDiscription();
  
          return;
  
      }  
  /*
      void addProduct(Product* pProduct)
      {
          m_products.push_back(pProduct);
  
      }
      void addDepartment(Catalog* pDepartment)
      {
          m_subDeptList.push_back(pDepartment);
  
      }
  */
  };
  
  int main(int argc, char** argv) {
  /*    
      Department megaStoreCatalog("catalog");
      Department stationary("Stationary");
      Product pen("pen", 5);
      stationary.addProduct(&amp;pen);
      Department stationaryLiquid("Stationary-Liquid");
      Product ink("Bril",30);
      stationaryLiquid.addProduct(&amp;ink);
      megaStoreCatalog.addDepartment(&amp;stationary);
      stationary.addDepartment(&amp;stationaryLiquid);
  
      megaStoreCatalog.addDiscount(10);
  
    */  
      return 0;
  }
  </code></pre>