hi everyone...
i know the code below has many other problems with it but it's in 'develope-"mental" stage' (if you know what i mean)..
it's going to be a list database employee payroll system when it grows up..
presently though, i have a wierd problem...
my overloaded friend function ostream for <<.
I am getting 'protected data' error C2248, when i try to compile.
However, a human friend of mine has run it fine on their machine sans errors. I am stumped. I have rebuilt, cleaned and even
openeed a new project ...
can anyone take a look and tell me if they see something?
thanks Michele
ps any comments on anything else will also be appreciated and
considered constructive...this is a big project for me, and I am still pretty much a newbie-green.
thanks again
Smilies disabled in post by SalemCode:// #include<iostream> using std::cin; using std::cout; using std::endl; using std::ostream; using std::istream; #include<list> using std::list; #include<iomanip> using namespace std; #include <fstream> using std::ifstream; using std::ofstream; #include <string> struct Name { char first[20]; char last[20]; }; struct EmployeeData { char type[20]; Name name; char ssn[12]; double rate; double commission; }; // Abstract base class definition // class employee // Declare a virtual base // class named employee { public: // Constructors for employee class employee(); employee(EmployeeData data); // Declare pure virtual functions virtual void print() = 0; virtual double pay() = 0; //Friend Function definitions / overloaded stream operators friend ostream & operator << ( ostream & output, const employee *n_employee ); protected: EmployeeData data; }; // End of the employee class definition // default constructor // required for multiple inheritance of virtual base class employee::employee() { strcpy(data.name.first, ""); strcpy(data.name.last, ""); strcpy(data.type, ""); strcpy(data.ssn, "000-00-0000"); data.rate = 0; data.commission = 0; } //employee constructor employee::employee(EmployeeData E_Data) { strcpy(data.name.first, E_Data.name.first); strcpy(data.name.last, E_Data.name.last); strcpy(data.type, E_Data.type); strcpy(data.ssn, E_Data.ssn); data.rate = E_Data.rate; data.commission = E_Data.commission; } //___________________________________________________ class hourly:virtual public employee { public: hourly(){}//needed for Salaried to be a base class hourly (EmployeeData E_Data, double hours); // pay function for the Engineer class virtual double pay(); // print function for the Engineer class virtual void print(); private: double hours; }; //hourly constructor hourly::hourly(EmployeeData E_Data, double hrs) { strcpy(data.name.first, E_Data.name.first); strcpy(data.name.last, E_Data.name.last); strcpy(data.type, E_Data.type); strcpy(data.ssn, E_Data.ssn); data.rate = E_Data.rate; data.commission = E_Data.commission; hours = hrs; } // Definition of the pay function for the hourly class // double hourly::pay() { if (hours <=40) return ((data.rate) * (hours)) ; else return ((data.rate) * (40))+((data.rate*1.5) * (hours-40)); } // Definition of the print function for the hourly class // void hourly::print() { cout << "Employee name : " << data.name.first << " , " << data.name.last << endl; cout << "Employee Type :" << data.type << endl; cout << "Social Security Number : "<< data.ssn <<endl; cout << setprecision(2); cout << setiosflags(ios::fixed | ios::showpoint); cout << "Pay is : $" << pay() << " dollars this month." << endl; cout << endl; } //end hourly member functions //____________________________________________________ class salary:virtual public employee { public: salary(){}//needed for Salaried to be a base class salary (EmployeeData E_Data, double sal); // pay function for the Engineer class virtual double pay(); // print function for the Engineer class virtual void print(); private: double annual_sal; }; //salary constructor salary::salary(EmployeeData E_Data, double sal) { strcpy(data.name.first, E_Data.name.first); strcpy(data.name.last, E_Data.name.last); strcpy(data.type, E_Data.type); strcpy(data.ssn, E_Data.ssn); data.rate = 0; data.commission = 0; annual_sal = sal; } // Definition of the pay function for the hourly class // double salary::pay() { return annual_sal / 12 ; } // Definition of the print function for the hourly class // void salary::print() { cout << "Employee name : " << data.name.first << " , " << data.name.last << endl; cout << "Employee Type :" << data.type << endl; cout << "Social Security Number : "<< data.ssn <<endl; cout << setprecision(2); cout << setiosflags(ios::fixed | ios::showpoint); cout << "Pay is : $" << pay() << " dollars this month." << endl; cout << endl; } //end hourly member functions //____________________________________________________ class Employee_Database { void showEmployeeMenu(); void getMenuSelection(); public: Employee_Database( const char* employee); ~Employee_Database(); void Run(); private: void Hire(); void Fire(); void Retire(); }; Employee_Database::Employee_Database( const char* employee) { } void Employee_Database::Hire() { } void Employee_Database::Fire() { } void Employee_Database::Retire() { } //Friend Function definitions / overloaded stream operators ostream &operator << ( ostream & output, const employee *n_employee ) { cout << left << setw(12) << n_employee->data.name.first << setw(12) << n_employee->data.name.last; return output; }//Fx //utility function //void enterData( EmployeeData &newWorker); void main() { //testcase EmployeeData newWorker; strcpy(newWorker.name.first, "John"); strcpy(newWorker.name.last, "Doe"); strcpy(newWorker.type, "SecurityGuard"); strcpy(newWorker.ssn, "111-11-1111"); newWorker.rate = 30.0; newWorker.commission = 0; EmployeeData newWorker2; strcpy(newWorker2.name.first, "Jane"); strcpy(newWorker2.name.last, "Doe"); strcpy(newWorker2.type, "Engineer"); strcpy(newWorker2.ssn, "222-22-2222"); newWorker.rate = 0; newWorker.commission = 0; hourly SecurityGuard( newWorker, 46 ); SecurityGuard.print(); salary Engineer( newWorker2, 40000 ); Engineer.print(); }//main /* void enterData( EmployeeData &newWorker) { cout << "\nOpening File.\n\n"; ifstream infile("PRO_IN.txt"); if(!infile){ cerr << "inFile could not be opened." << endl; exit(1); } typedef list <string> Em_list; Em_List edata; while( infile ) { if (infile) edata.insert(test.end(), &newWorker); } //end while } // end function */



LinkBack URL
About LinkBacks


