title: C++ mistakes with linking virtual function
body: <p>I got a weird problem with C++. Well, I tried to write an a simple program on seven separated files. Everything was going well, until an error occurred which caused that I can't go any further. Can someone tell what have I done wrong ?</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "item.hpp"
  using namespace std;
  
  int main()
  {
  
  int x;
  Magazine some_magazine;
  Book some_book;
  
  Item *wsk_instr;
  
  cout &lt;&lt; "Witamy w ksiegarni" &lt;&lt; endl &lt;&lt; endl;
  cout &lt;&lt; "Wcisnij 1 aby kupic ksiazke" &lt;&lt; endl;
  cout &lt;&lt; "Wcisnij 2 aby sprzedac ksiazke" &lt;&lt; endl;
  cout &lt;&lt; "Wcisnij 3 aby zobaczyc jakie ksiazki mamy" &lt;&lt; endl;
  cin &gt;&gt; x;
  
  switch (x)
  {
      case 1:
          cout &lt;&lt; "Kup ksiazke" &lt;&lt;endl;
          wsk_instr = &amp;some_magazine;
          wsk_instr -&gt; show();
          cout &lt;&lt; "Ktora ksiazke chcesz kupic?" &lt;&lt; endl;
          cout &lt;&lt; "Ksiazka pierwsza - 1, ksiazka druga - 2, ksiazka trzecia - 3" &lt;&lt; endl;
          wsk_instr = &amp;some_book;
          wsk_instr -&gt; sell();
          break;
  
      case 2:
          cout &lt;&lt; "Sprzedaj ksiazke" &lt;&lt; endl;
          cout &lt;&lt; "Jaka ksiazke chcesz sprzedać? Podaj tytul:\t";
          wsk_instr = &amp;some_book;
          wsk_instr -&gt; buy();
          break;
  
      case 3:
          cout &lt;&lt; "Pokaz co mamy na stanie" &lt;&lt; endl;
          wsk_instr = &amp;some_magazine;
          wsk_instr -&gt; show();
          break;
  
      default:
          cout &lt;&lt; "Nie wybrales nic" &lt;&lt; endl;
          break;
  }
  }    
  </code></pre>
  
  <p>item.cpp &amp; item.hpp</p>
  
  <pre><code>item.cpp
  #include &lt;iostream&gt;
  
  void buy() {};
  void sell() {};
  void show() {};
  
  item.hpp
  #ifndef item_hpp
  #define item_hpp
  
  class Item {
  public:
  void virtual buy();
  void virtual sell();
  void virtual show();
  };
  #endif /* item_h */
  </code></pre>
  
  <p>magazine.cpp &amp; magazine.hpp</p>
  
  <pre><code>magazine.cpp
  #include &lt;iostream&gt;
  #include "magazine.hpp"
  #include "book.hpp"
  
  //dodawanie elementu na koniec wektora
  void Magazine::add() {
  std::cout &lt;&lt; "Jaka ksiazke chcesz sprzedać? Podaj tytul:\t";
  std::string book_title;
  std::cin &gt;&gt; book_title;
  table_of_books.push_back(book_title);
  }
  
  //usuwanie ostatniego elementu wektora
  void Magazine::remove() {
  std::cout &lt;&lt; "Ktora ksiazke chcesz kupic? Podaj numer:\t";
  int choose;
  std::cin &gt;&gt; choose;
  table_of_books.erase(table_of_books.begin() + choose);
  }
  
  //pokazywanie wielkosci wektora (ilosci elementow w nim)
  void Magazine::show() {
  std::cout &lt;&lt; "W magazynie jest: " &lt;&lt; table_of_books.size() &lt;&lt; " ksiazek. A oto one:" &lt;&lt; std::endl;
  //wyswietlanie wszystkich ksiazek jakie sa w wektorze
  for(int counter = 0; counter &lt; table_of_books.size(); counter ++) {
      std::cout &lt;&lt; table_of_books[counter] &lt;&lt; std::endl;
      }    
  }
  
  
  magazine.hpp
  #ifndef magazine_hpp
  #define magazine_hpp
  #include &lt;vector&gt;
  #include "item.hpp"
  #include "book.hpp"
  
  class Magazine : public Item {
  std::vector &lt;std::string&gt; table_of_books { "Potop", "Zemsta", "Dziady", };
  
  public:
  void add();
  void remove();
  void show();
  };
  #endif /* magazine_hpp */
  </code></pre>
  
  <p>book.cpp &amp; book.hpp</p>
  
  <pre><code>book.cpp
  #include &lt;iostream&gt;
  #include "book.hpp"
  #include "magazine.hpp"
  
  void Book::buy() {
  add_book_to_the_magazine.add();
  }
  
  void Book::sell() {
  delete_book_from_the_magazine.remove();
  }
  
  book.hpp
  #ifndef book_hpp
  #define book_hpp
  #include "item.hpp"
  #include "magazine.hpp"
  
  class Book : public Item {
  
  Magazine add_book_to_the_magazine;
  Magazine delete_book_from_the_magazine;
  
  void buy();
  void sell();
  };
  
  #endif /* book_hpp */
  </code></pre>
  
  <p>My problem is with these two lines:</p>
  
  <p>main.cpp</p>
  
  <pre><code>Magazine some_magazine;
  Book some_book;
  </code></pre>
  
  <p>Xcode says that: unknown type name 'Magazine' and 'Book'. Sounds like there is a problem with linking? But class magazine and class book are set to public for class item. So, what's the problem?   </p>