??? No overloaded function takes 2 parameters ???

How do i fix this error in the below code.


//C:My ProjectsCalcSalaryMain.cpp(38) : error C2661: 'Waiter::Waiter' : no overloaded function takes 2 parameters
//C:My ProjectsCalcSalaryMain.cpp(39) : error C2661: 'Programmer::Programmer' : no overloaded function takes 2 parameters


-----------------------------------------------------------------------
#include

class Job

{
public:
Job() {dSalary = 0, dHours = 0;}
double getSalary() const {return dSalary;}
protected:
double dSalary;
double dHours;
};
////////////////////////////////////////////////////////////////////
class Waiter : public Job

{
public:
Waiter() {dHours = 0, dWaiterRate = 0;}
double getSalary() const {return (dHours * dWaiterRate);}
protected:
double dWaiterRate;
};
////////////////////////////////////////////////////////////////////
class Programmer : public Job

{
public:
Programmer() {dHours = 0, dProgrammerRate = 0;}
double getSalary() const {return (dHours * dProgrammerRate);}
protected:
double dProgrammerRate;
};
////////////////////////////////////////////////////////////////////
class GetPay
{
public:
GetPay()
{
array[1] = new Waiter(45, 7);
array[2] = new Programmer(55, 15);
}
~GetPay()
{
delete array[1];
delete array[2];
}
Job* array[3];
};
////////////////////////////////////////////////////////////////////
int main()
{
GetPay GetPay;

cout << "A waiter makes: " << GetPay.array[1]->getSalary() << endl;
cout << "A programmer makes: " << GetPay.array[2]->getSalary() << endl;

return 0;

}

Comments

  • [b][red]This message was edited by stober at 2003-12-31 16:49:9[/red][/b][hr]
    : How do i fix this error in the below code.

    [blue]Well, if you wrote that code you should know that the Waiter and Programmer classs do not have a constructor that takes two parameters.

    How to fix the problems? Add a contructor to each of the classes that takes the two parameters that you are attemting to pass. [/blue]

    :
    :
    : //C:My ProjectsCalcSalaryMain.cpp(38) : error C2661: 'Waiter::Waiter' : no overloaded function takes 2 parameters
    : //C:My ProjectsCalcSalaryMain.cpp(39) : error C2661: 'Programmer::Programmer' : no overloaded function takes 2 parameters
    :
    :
    : ----------------------------------------------------------------------[code]
    : #include
    :
    : class Job
    :
    : {
    : public:
    : Job() {dSalary = 0, dHours = 0;}
    : double getSalary() const {return dSalary;}
    : protected:
    : double dSalary;
    : double dHours;
    : };
    : ////////////////////////////////////////////////////////////////////
    : class Waiter : public Job
    :
    : {
    : public:
    : Waiter() {dHours = 0, dWaiterRate = 0;}
    : double getSalary() const {return (dHours * dWaiterRate);}
    : protected:
    : double dWaiterRate;
    : };
    : ////////////////////////////////////////////////////////////////////
    : class Programmer : public Job
    :
    : {
    : public:
    : Programmer() {dHours = 0, dProgrammerRate = 0;}
    : double getSalary() const {return (dHours * dProgrammerRate);}
    : protected:
    : double dProgrammerRate;
    : };
    : ////////////////////////////////////////////////////////////////////
    : class GetPay
    : {
    : public:
    : GetPay()
    : {
    : array[1] = new Waiter(45, 7);
    [red]See the declaration for Programmer and Waiter class[/red]
    : array[2] = new Programmer(55, 15);
    : }
    : ~GetPay()
    : {
    : delete array[1];
    : delete array[2];
    : }
    : Job* array[3];
    : };
    : ////////////////////////////////////////////////////////////////////
    : int main()
    : {
    : GetPay GetPay;
    :
    : cout << "A waiter makes: " << GetPay.array[1]->getSalary() << endl;
    : cout << "A programmer makes: " << GetPay.array[2]->getSalary() << endl;
    :
    : return 0;
    :
    : }
    [/code]:
    :







  • how do i do that
  • : how do i do that
    :

    You should have already read about constructors. If not, then re-read the chapter(s) -- the two classes already have one constructor so just add another with the appripriate parameters. A class can have as many different constructors as needed. Here's an example:
    [code]
    class A
    {
    A(); // constructor with no parameters
    A(int x); // constructor with one parameter
    A(int x, int y); // constructor with two parameters
    // etc. etc for as many constructors as necessary
    };
    [/code]

  • I did that. Look at my code once more. I more than likely messed up somewhere else, but i'm just a newbie so what do i know.
  • [b][red]This message was edited by stober at 2004-1-1 4:55:7[/red][/b][hr]
    : I did that. Look at my code once more. I more than likely messed up somewhere else, but i'm just a newbie so what do i know.
    :


    I'm from the "Show Me" state -- I don't see it in your first post. It wants something like this:

    [code]
    class Waiter : public Job
    :
    : {
    : public:
    : Waiter() {dHours = 0, dWaiterRate = 0;}
    [red] Waiter(double hours, double rate)
    {dHours = hours, dWaiterRate = rate;}[/red]
    : double getSalary() const {return (dHours * dWaiterRate);}
    : protected:
    : double dWaiterRate;
    : };
    [/code]





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories