Help - I am having the following errors repeatedly so I know it is a consistent mistake I am making but I just can’t see what it is. I already fixed many other errors and now it’s just this.....so close...... :confused:

My errors are the following. I did not put all of them as it is a repeated mistake. Every time I use my object to call a member function (such as a set, get, or other function) it gives me the following error. I have a 2nd program that is doing this as well….so I am not sure what I am misunderstanding.

Sample of the errors are:

.cpp(56) : error C2228: left of '.setLast' must have class/struct/union
.cpp(60) : error C2228: left of '.setFirst' must have class/struct/union
.cpp(64) : error C2228: left of '.setSalary' must have class/struct/union
.cpp(68) : error C2228: left of '.setLast' must have class/struct/union

.cpp(80) : error C2228: left of '.getFirst' must have class/struct/union
.cpp(80) : error C2228: left of '.getLast' must have class/struct/union

.cpp(85) : error C2228: left of '.raise' must have class/struct/union

My code is:

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

// program used C++ standard string class
#include <string>
using std::string;
using std::getline;


// include definition of class Employee from Employee.h
#include "Employee.h"

// function main begins program execution
int main()
{
   // in class Employee have the two objects employee 1 and employee 2
   Employee employee1();        // create the first Employee object
   Employee employee2();        // create the second Employee object


   string employee1Last;
   string employee1First;
   int employee1Salary;

   string employee2Last;
   string employee2First;
   int employee2Salary;


   // prompt user to enter input and obtain user input through the set function
   cout << "\nEnter employee 1's last name: " ;
   getline(cin,employee1Last);
   employee1.setLast(employee1Last); 

   cout << "\nEnter employee 1's first name: " ;
   getline(cin,employee1First);
   employee1.setFirst(employee1First);

   cout << "\nEnter employee 1's salary: ";
   cin >> employee1Salary;
   employee1.setSalary(employee1Salary);

    cout << "\n\nEnter employee 2's last name: " ;
   getline(cin,employee2Last);
   employee2.setLast(employee2Last); 

   cout << "\nEnter employee 2's first name: " ;
   getline(cin,employee2First);
   employee2.setFirst(employee2First);

   cout << "\nEnter employee 2's salary: ";
   cin >> employee2Salary;
   employee2.setSalary(employee2Salary);


   // display their initial information and salary
   cout << "The initial salary for " << employee1.getFirst() << employee1.getLast() 
   << "is " << employee1.getSalary()
   << "\nThe initial salary for " << employee2.getFirst() << employee2.getLast << "is " 
   << employee2.getSalary() << endl;

   // calculate raise
   employee1.raise();
   employee2.raise();


   // display their new salary with a 10 percent raise
   cout << "The new salary with a 10 percent raise for " << employee1.getFirst() 
   << employee1.getLast() << "is " << employee1.getSalary()
   << "\nThe new salary with a 10 percent raise for " << employee2.getFirst() 
   << employee2.getLast() << "is " << employee2.getSalary() << endl;

   return 0;

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This is simple to fix ... relax

Employee employee1(); // <- actually declares a function returning an Employee
// instead use ...
Employee employee1;

If the Employee's constructor would take argument(s), then you could have it like

string FirstName, LastName;
Employee employee1(FirstName, LastName);

Regarding code tags, the ending tag is [/code].

This question has already been answered. Start a new discussion instead.