title: creating an array of objects in c++
body: <p>I'm trying to create an array of objects in c++.</p>
  
  <p>I'm creating a employee object, from my constructor in my company class here:</p>
  
  <pre><code>employee obj(int tempIdNum, double tempBase, double tempSales, double tempRate);
  
  emp[tempcount]=obj;  (this doesn't work?)
  </code></pre>
  
  <p>Emp is the name of the array which is defined here, located in my company h file.</p>
  
  <pre><code> Employee emp[4]; 
  </code></pre>
  
  <p>sorry commission =employee.....
  here is my commission(employee) class cpp</p>
  
  <pre><code>    using namespace std;
  
  
  //----------------------------------------
  //Name: default constructor
  //Purpose: create a new object with attributes set to zero
  //Parameters: none
  //Returns: none
  //----------------------------------------
  Commission::Commission()
  {
      //cout &lt;&lt; "In default constructor of Commission class" &lt;&lt; endl;
      idNum = 0;
      base  = 0.0;
      rate  = 0.0;
      sales = 0.0;
  }
  
  
  //----------------------------------------
  //Name: initializing constructor
  //Purpose: initialize all attributes
  //Parameters:
  //  idNum - new value for id Num
  //  base -  new value for base amount
  //  sales - new value for sales amount
  //  rate -  new value for rate fraction
  //Returns:  none  
  //----------------------------------------       
  Commission::Commission(int idNum, double base, double sales, double rate)
  {
      //cout &lt;&lt; "In initializing constructor of Commission class" &lt;&lt; endl;
      this-&gt;idNum = idNum;    
      this-&gt;base  = base;
      this-&gt;sales = sales;
      this-&gt;rate  = rate;
  }
  
  //----------------------------------------
  //Name: copy constructor
  //Purpose: constructor a new object from an existing object
  //Parameters: 
  //  emp - current employee object
  //Returns: none
  //----------------------------------------
  Commission::Commission(const Commission&amp; emp)
  {
      //cout &lt;&lt; "In copy constructor of Commission class" &lt;&lt; endl;
      idNum = emp.idNum;
      base  = emp.base;
      sales = emp.sales;
      rate  = emp.rate;
  }
  
  //----------------------------------------
  //Name: operator=
  //Purpose: The copy assignment method copies the rhs object
  //  into the lhs object
  //Parameters: 
  //  rhs - object on the right hand side of the = sign
  //Returns: nothing
  //----------------------------------------
  void Commission::operator=(const Commission&amp; rhs)
  {
      //cout &lt;&lt; "In copy assignment of Commission class" &lt;&lt; endl; 
      idNum = rhs.idNum;
      base  = rhs.base;
      sales = rhs.sales;
      rate  = rhs.rate;
  }
  
  //----------------------------------------
  //Name: destructor
  //Purpose: destruct object and print id num
  //Parameters: none
  //Returns: 
  //----------------------------------------
  Commission::~Commission()
  {
      //cout &lt;&lt; "In destructor of Commission class for id num: " &lt;&lt; idNum &lt;&lt; endl;
  }
  
  //----------------------------------------
  //Name: setIdNum
  //Purpose: set id num to a new value
  //Parameters: 
  //  newIdNum - new value for id num
  //Returns: true if new id num is between 0 and 999, inclusively
  //   otherwise false
  //----------------------------------------
  bool Commission::setIdNum(int newIdNum)
  {
      if (newIdNum &gt;= 0 &amp;&amp; newIdNum &lt;= 999)
      {
          idNum = newIdNum;
          return true;
      }
      else
          return false;
  }
  
  //----------------------------------------
  //Name: setBase
  //Purpose: set base to a new value
  //Parameters: 
  //  newBase - new value for base
  //Returns: true if new base is greater zero; otherwise false
  //----------------------------------------
  bool Commission::setBase(double newBase)
  {
      if (newBase &gt; 0.0)
      {
          base = newBase;
          return true;
      }
      else
          return false;
  }
  
  //----------------------------------------
  //Name: setRate
  //Purpose: set the commission rate
  //Parameters: 
  // newRate - new commission rate as a percentage
  //Returns: true if rate greater than zero and less than or equal to 0.20
  //----------------------------------------
  bool Commission::setRate(double newRate) 
  {
      if (newRate &gt; 0.0 &amp;&amp; newRate &lt;= 0.20)
      {
          rate = newRate;
          return true;
      }
      else
          return false;
  }
  
  //----------------------------------------
  //Name: setSales
  //Purpose: set sales to a new amount
  //Parameters:
  //  newSales - new amount of sales
  //Returns: true if sales is greater than or equal to zero; otherwise false
  //----------------------------------------
  bool Commission::setSales(double newSales) 
  {
      if (newSales &gt;= 0.0)
      {
          sales = newSales;
          return true;
      }
      else
          return false;
  }
  
  //----------------------------------------
  //Name: getIdNum
  //Purpose: get the current id num
  //Parameters: none
  //Returns: current id num
  //----------------------------------------
  int Commission::getIdNum()  
  {
      return idNum;
  }
  
  //----------------------------------------
  //Name: getBase
  //Purpose: get the current base amount of salary
  //Parameters: none
  //Returns: current base salary
  //----------------------------------------
  double Commission::getBase()  
  {
      return base;
  }
  
  //----------------------------------------
   //Name: getRate
  //Purpose: get the current commission rate as fraction
  //Parameters: none
  //Returns: current commission rate
  //----------------------------------------
  double Commission::getRate()
  {
      return rate;
  }
  
  //----------------------------------------        
  //Name: getSales
  //Purpose: get current amount of sales
  //Parameters: none
  //Returns: current amount of sales
  //----------------------------------------
  double Commission::getSales()
  {
      return sales;
  }
  
  //----------------------------------------
  //Name: calcSalary
  //Purpose: calculate commission as base + sales x commission rate
  //Parameters: none
  //Returns: amount of commission
  //----------------------------------------
  double Commission::calcSalary() 
  {
      return (base + sales * rate);
  }
  
  
  
  
  
  and here is its .h
  
  
      #include &lt;string&gt;
  using namespace std;
  
  #ifndef Commission_H
  #define Commission_H
  
  class Commission
  {
      private:
          int    idNum;   //id number of employee
          double base;    //base salary
          double rate;    //rate of commission as fraction
          double sales;   //sales on which commission rate applies
  
      public:
          //constructors
          Commission();               //default constructor
          Commission(int idNum, double base, double sales, double rate);  //constructor with idNum
          Commission(const Commission&amp; orig);  //copy constructor
  
          //destructor
          ~Commission( );
  
          //copy assignment
          void operator=(const Commission&amp; rhs);
  
          //mutators
          bool setIdNum(int idNum);        //set id num
          bool setBase(double base);       //set base salary
          bool setRate(double rate);       //set rate of commission
          bool setSales(double sales);     //set amount of sales for commission
  
          //accessors
          int    getIdNum();    //get id num;
          double getBase();     //get base salary
          double getRate();     //get commission rate
          double getSales();    //get sales for commission
  
          //calculate salary
          double calcSalary();  //calculate commission  
  };        
  
  #endif
  </code></pre>