Compiler error c2228

This is a discussion on Compiler error c2228 within the C++ Programming forums, part of the General Programming Boards category; I've been working on this little project for a while now. Everytime I get close to completing it, something goes ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    9

    Compiler error c2228

    I've been working on this little project for a while now. Everytime I get close to completing it, something goes wrong. Can someone please tell me what this error means:


    error C2228: left of '.calculatePay' must have class/struct/union


    Here is the code. Thanks

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    
    
    const double _payRate = 3.75;
    
    class Employee
    {
    private:
    	int    _empId;		// Employee Id.
    
    //	double	_hoursWorked;	// Hours Worked.
    
    public:
    	Employee( );			// Constructor.
    	Employee( int empId );		// Overloaded Constructor.
    	double calculatePay( /*int*/ double hoursWorked );	// Calculates the Employees pay.
    	double salary;
    	void setEmpId( int empId );		// Mutator Method - allows you to set the employee id.
    	int  getEmpId( );			// Accessor Method - allows you to get the employee id. 
    	void setSalaried();			//
    	bool getSalaried();			//
    };
    
    // Constructor.
    Employee::Employee()
    {
    	this->_empId = 1;
    	//this->_payRate = 5.33;
    	
    //	this->_hoursWorked = 10.0;
    }
    
    Employee::Employee( int empId  )
    {
    	this->_empId = empId;
    	//this->_payRate = payRate;
    	
    }
    
    // Calculates the Employee's pay based upon the _payRate and _hoursWorked.
    double Employee::calculatePay( /*int*/ double hoursWorked ) 
    {
    	return _payRate * hoursWorked;
    }
    
    // Sets the Employee Id
    void Employee::setEmpId( int empId )
    {
    	this->_empId = empId;
    }
    
    // Gets the employee id.
    int Employee::getEmpId( )
    {
    	return this->_empId;
    }
    
    
    // Main C++ function.
    int _tmain(int argc, _TCHAR* argv[])
    {
    	
    	double emp1Pay = 0.0;	
    	double emp2Pay = 0.0;
    	double emp3Pay = 0.0;
    	double totalPay = 0.0;	
    
    	Employee emp1( 1);
    	Employee emp2( 2 );
    	Employee emp3( 3 );
    
    
    	double emp1Hours, emp2Hours, emp3Hours;
    	
    	cout << "Please type number of hours for first employee\t: ";
    	cin >>  emp1Hours;
    	cout<<  _payRate * emp1Hours<<endl; 
    	
    	cout<< "Please type number of hours for second employee\t: ";
    	cin>> emp2Hours;
    	cout<< _payRate * emp2Hours<<endl;
    
    	cout<<"Please type number of hours for third employee\t: ";
    	cin>>emp3Hours;
    	cout<<_payRate * emp3Hours<<endl;
    
    
    	
    
    	//cout << "Employee " << emp.getEmpId( ) << "'s salary is : " << emp.calculatePay( 40 );
    
    	
    	emp1Pay = emp.calculatePay( emp1Hours );
    	totalPay += emp1Pay;
    	
    	emp2Pay = emp.calculatePay( emp2Hours );
    	totalPay += emp2Pay;
    
    	emp3Pay = emp.calculatePay( emp3Hours );
    	totalPay += emp3Pay;
    
    	cout << endl << "Employee ID" << setw(15) << "Pay" << endl;
    	cout << "----------------------------" << endl;
    	cout << emp1.getEmpId( )  << setw(27) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << emp1Pay << setiosflags( ios::left ) << endl;
    	cout << emp2.getEmpId( ) << setw(27) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << emp2Pay << setiosflags( ios::left ) << endl;
    	cout << emp3.getEmpId( ) << setw(27) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << emp3Pay << setiosflags( ios::left ) << endl;
    	cout << "----------------------------" << endl;
    	cout << "Total" << setw(23) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << totalPay << setiosflags( ios::left ) << endl;
    
    
    	cout << endl << endl << "Please press a key and then press enter to quit." << endl;
    	
    	char a;
    	cin >> a;
    
    	return 0;
    }
    Last edited by <showMe>; 06-29-2006 at 09:43 AM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    	emp1Pay = emp.calculatePay( emp1Hours );
    	totalPay += emp1Pay;
    	
    	emp2Pay = emp.calculatePay( emp2Hours );
    	totalPay += emp2Pay;
    
    	emp3Pay = emp.calculatePay( emp3Hours );
    	totalPay += emp3Pay;
    What is emp?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    emp1Pay = emp.calculatePay( emp1Hours );
    emp has not been declared as an object of Employee type
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 05:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21