Discussion:
[Dev-C++] Derived Class not redefining function
Opacki, Joseph
2003-10-17 13:26:15 UTC
Permalink
Can someone please tell me why my main() function isn't accepting the
redefined function of my base class? Everything seems to be compiling
correctly, but the base class printCheck function is executing and not the
derived class function.

Here are the excepts of code:

// -- BASE CLASS -- //
void Employee::printCheck() const
{
cout << "\nERROR: print_check FUNCTION CALLED FOR AN \n"
<< "UNDIFFERENTIATED EMPLOYEE. Aborting program.\n"
<< "Check with the author of the progrm about this bug.\n";
exit(1);
}

// -- DERIVED CLASS -- //
void HourlyEmployee::printCheck()
{
setNetPay(hours * wageRate);

cout <<
"\n__________________________________________________________\n";
cout << "Pay o the order of " << getName() << endl;
cout << "The sum of " << getNetPay() << " Dollars\n";
cout <<
"\n__________________________________________________________\n";
cout << "Check Stub: NOT NEGOTIABLE:\n";
cout << "Employee Number: " << getSSN() << endl;
cout << "Hourly employee.\n Hours Worked: " << hours
<< " Rate: " << wageRate << " Pay: " << getNetPay() << endl;
cout <<
"\n__________________________________________________________\n";
}

// -- MAIN -- //
HourlyEmployee joe;
joe.setName("Mighty Joe");
joe.setSSN("123-65-6547");
joe.setRate(50.20);
joe.setHours(40);
cout << "Check for " << joe.getName() << " for " << joe.getHours() << "
hours\n";
joe.printCheck();
^this call is where thing go crazy
Per Westermark
2003-10-17 14:12:19 UTC
Permalink
If you look a bit closer at the two methods, you will notice the different
signatures

Employee::printCheck() is const
HourlyEmployee::printCheck() isn't const

/Per W
Post by Opacki, Joseph
Can someone please tell me why my main() function isn't accepting the
redefined function of my base class? Everything seems to be compiling
correctly, but the base class printCheck function is executing and not the
derived class function.
// -- BASE CLASS -- //
void Employee::printCheck() const
{
cout << "\nERROR: print_check FUNCTION CALLED FOR AN \n"
<< "UNDIFFERENTIATED EMPLOYEE. Aborting program.\n"
<< "Check with the author of the progrm about this bug.\n";
exit(1);
}
// -- DERIVED CLASS -- //
void HourlyEmployee::printCheck()
{
setNetPay(hours * wageRate);
cout <<
"\n__________________________________________________________\n";
cout << "Pay o the order of " << getName() << endl;
cout << "The sum of " << getNetPay() << " Dollars\n";
cout <<
"\n__________________________________________________________\n";
cout << "Check Stub: NOT NEGOTIABLE:\n";
cout << "Employee Number: " << getSSN() << endl;
cout << "Hourly employee.\n Hours Worked: " << hours
<< " Rate: " << wageRate << " Pay: " << getNetPay() << endl;
cout <<
"\n__________________________________________________________\n";
}
// -- MAIN -- //
HourlyEmployee joe;
joe.setName("Mighty Joe");
joe.setSSN("123-65-6547");
joe.setRate(50.20);
joe.setHours(40);
cout << "Check for " << joe.getName() << " for " << joe.getHours() << "
hours\n";
joe.printCheck();
^this call is where thing go crazy
-------------------------------------------------------
This SF.net email sponsored by: Enterprise Linux Forum Conference & Expo
The Event For Linux Datacenter Solutions & Strategies in The Enterprise
Linux in the Boardroom; in the Front Office; & in the Server Room
http://www.enterpriselinuxforum.com
_______________________________________________
Dev-cpp-users mailing list
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
Hossein Haeri
2003-10-19 16:24:11 UTC
Permalink
Hi Per,
Post by Per Westermark
If you look a bit closer at the two methods, you will notice the different
signatures
Employee::printCheck() is const
HourlyEmployee::printCheck() isn't const
Waw, eagle eyes. But why should it call the const version?

Thanks,
--Hossein
--
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
Continue reading on narkive:
Loading...