title: How to use base class constructor
body: <p>I wanted to define a constructor for a derived class and use the base class constructor which I have defined. I have commented the derived class constructor code. </p>
  
  <pre><code>#include "stdafx.h"
  #include "iostream"
  #include "stdio.h"
  #include "string"
  
  using namespace std;
  
  class person{
      private:
          string name;
          int age;
  
      public :
          person(int,string); //constructor
   };
  
  class student : public person{ //derived class
      private :
          string teacher;
      public :
          student(string);
  };
  
  person :: person(int newage,string newname){
  
      age = newage;
      name = newname;
      cout &lt;&lt;age &lt;&lt; name;
  }
  /* How do I define the derived class constructor , so that by default
    it calls base class person(int,string) constructor.
  student :: student(string newteacher){
      teacher = newteacher;
      cout&lt;&lt;teacher;
  
  }
   */
  int _tmain(int argc, _TCHAR* argv[])
  {
     person p(20,"alex");
     student("bob");
  
      return 0;
  }
  </code></pre>
  
  <p>Adding more details: </p>
  
  <p>I want to define my derived class constructor in a way , that I can call base class constructor within my derived class constructor.Right now if I uncomment my derived class constructor I get the following error "no default constructor exists for class person.". Is it possible to do something like: </p>
  
  <pre><code> student object("name",10,"teacher_name")
  </code></pre>
  
  <p>name ,age should be initialized using base class constructor and teacher_name should be initialized using derived class constructor. I am new to C++ , so if something like this is not possible , please let me know. </p>