We help IT Professionals succeed at work.

Constructor Default Parameter Problem

prain
prain asked
on
210 Views
Last Modified: 2012-05-04
Ok this seems to be a simple question. But I cannot figure out.
I have an Employee class defined in Employee.h, with a constructor for which I intend to have default parameters.
So here it is....

class Employee
{
   char name [81];
   double wage;
 public :
      
         Employee(char *nm , double wg);

       void set_name (char *n);
       char * get_name () ;
       void set_wage (double w);
       double get_wage();
};
------------------------------------------------------------
Now I have the implementation with default values in the constructor...
#include "Employee.h"
#include "string.h"

Employee::Employee(char *nm = "Blank", double wg = 0.0)
{
       strcpy (name , nm);
     wage = wg;
}

void Employee:: set_name (char *n)
      {
         strcpy (name , n);
      }

char* Employee::get_name()
      {
        return name;
      }

void Employee::set_wage(double w)
      {
         wage = w;
      }

double Employee :: get_wage()
      {
        return wage;
      }
-----------------------------------------------------
So now I write a driver to test two the objects.
#include <iostream>
#include "Employee.h"
using namespace std;
main()
{
  Employee  e1;
  Employee  e2("Joe", 1000.0);
   
  return 0;
}

---------------------------------------------------
Why do I get a compiler error in the line :

Employee e1;   ????

Since I am using a constructor with default parameters, why does it not allowing me to construct the object????
I am getting  "no appropriate default constructor available" error while compiling.
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.