title: C++ class and inheritance error: undefined reference to derived class
body: <p>I am attempting to make part of a program that uses a bank account class as the base class and checking and savings as the derived classes.  I have been trying to set up the basic framework before I do any fancy data handling and I've followed some tutorials to get a better understanding of classes and inheritance.</p>
  
  <p>I have looked for answers but the answers I have found don't seem to be my problem but I might just need another set of eyes on my code.</p>
  
  <p>the compiler errors:</p>
  
  <blockquote>
    <p>In function <code>main':
    badriver.cpp:20: undefined reference to</code>Checking::getAccount()'
    badriver.cpp:23: undefined reference to <code>Checking::setAccount(int)'
    badriver.cpp:24: undefined reference to</code>Savings::setAccount(int)'
    badriver.cpp:26: undefined reference to `Checking::getAccount()'</p>
  </blockquote>
  
  <p>badriver.cpp</p>
  
  <pre><code>#include "BankAccount.cpp"
  #include "Checking.cpp"
  #include "Savings.cpp"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main(){
  
     Checking c;
     Savings s;
  
     cout &lt;&lt; "Checking: " &lt;&lt; c.getAccount() &lt;&lt; " - Type: " &lt;&lt; c.getType() &lt;&lt; endl;
     cout &lt;&lt; "Savings: " &lt;&lt; s.getAccount() &lt;&lt; " - Type: " &lt;&lt; s.getType() &lt;&lt; endl;
  
     c.setAccount(9);
     s.setAccount(15);
  
     cout &lt;&lt; "New Checking: " &lt;&lt; c.getAccount() &lt;&lt; endl;
     cout &lt;&lt; "New Savings: " &lt;&lt; s.getAccount() &lt;&lt; endl;
         return 0;
      }
  </code></pre>
  
  <p>BankAccount.h</p>
  
  <pre><code>#ifndef BANKACCOUNT_H
  #define BANKACCOUNT_H
  #include &lt;string&gt;
  using std::string;
  using std::ostream;
  using std::istream;
  
  class BankAccount{
  
  private:
     int myAccount;
  
     const char* color;
  
  public:
     // default constructor
     BankAccount();
     BankAccount(int account);
     virtual ~BankAccount();
  
     virtual void setAccount(int)=0;
     int getAccount();
  //    
  //    void setSAccount(int);
  //    int getSAccount();
  //    
     virtual const char* getColor();                                            
     virtual const char* getType() = 0; 
     //virtual const char* getCType() = 0; 
  
  protected:
     void setColor(const char*);   
  
  };
  
  #endif // BANKACCOUNT_H
  </code></pre>
  
  <p>BankAccount.cpp</p>
  
  <pre><code>#include "BankAccount.h"
  #include "Checking.h"
  #include "Savings.h"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  // default constructor
  BankAccount::BankAccount(){
     account = 1;
  }
  
  BankAccount::~BankAccount(){}
  
  // void BankAccount::setAccount(int account){
  //    myAccount  = account;
  // }
  
  int BankAccount::getAccount(){
     return myAccount ;
  }
  
  BankAccount::BankAccount(int account){
     myAccount = account;
  }
  
  const char* BankAccount::getColor(){
     return color;
  }
  
  void BankAccount::setColor(const char* c){
     color = c;
  }
  </code></pre>
  
  <p>Checking.h</p>
  
  <pre><code>#ifndef CHECKING_H
  #define CHECKING_H
  #include "BankAccount.h"
  #include &lt;string&gt;
  using std::string;
  using std::ostream;
  using std::istream;
  
  class Checking : public BankAccount{
  
  private:
     const char* type;
  
  public:
     Checking();
     virtual ~Checking();
     void setAccount(int account);
  
  
     virtual const char* getType();
  
     void setChecking(int);
     int getChecking();
  };
  
  #endif //CHECKING_H
  </code></pre>
  
  <p>Checking.cpp</p>
  
  <pre><code>#include "Checking.h"
  #include &lt;string&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  Checking::Checking() : BankAccount(1), type("Checking"){}
  
  Checking::~Checking(){}
  
  BankAccount::~BankAccount(){}
  
  void BankAccount::setAccount(int account){
     myAccount  = account;
  }
  
  
  const char* Checking::getType(){
     return type;
  }   
  </code></pre>
  
  <p>Savings.h</p>
  
  <pre><code>#ifndef  SAVINGS_H
  #define SAVINGS_H
  #include "BankAccount.h"
  #include &lt;string&gt;
  using std::string;
  using std::ostream;
  using std::istream;
  
  class Savings: public BankAccount{
  
  private:
     const char* type;
  
  public:
     Savings();
     virtual ~Savings();
     void setAccount(int account);
  
     virtual const char* getType();
  
     void setSavings(int);
     int getSavings();
  };
  
  #endif // SAVINGS_H
  </code></pre>
  
  <p>Savings.cpp</p>
  
  <pre><code>#include "Savings.h"
  #include &lt;string&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  Savings::Savings() : BankAccount(2), type("Savings"){}
  
  Savings::~Savings(){}
  
  BankAccount::~BankAccount(){}
  
  void BankAccount::setAccount(int account){
     myAccount  = account;
  }
  
  const char* Savings::getType(){
     return type;
  }   
  </code></pre>
  
  <p>Thanks for any help pointing me in the right direction.</p>