I'm just getting started with classes and objects, and having a little trouble. I just filled out some of the basic parts of the program, because I figured I'd have trouble with the class/object implementation. I get the error "error C2228: left of '.determineSalary' must have class/struct/union type" in regards to line 23, which I've put a smiley next to. Edit: oops, didn't work out quite right, it's the line that says "companyPayroll.determineSalary();"

I'm not quite sure what the deal is, I've looked through my book, trying to figure it out, I thought it might have something to do with constructors...but I don't understand constructors that well yet either! Thanks guys/gals.

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

class Payroll
{
public:
    void determineSalary();
};    //End class Payroll

int main()
{

    Payroll companyPayroll();
    companyPayroll.determineSalary(); 
    void setPayroll();
    return 0;

}

void Payroll::determineSalary()    {
    int paycode;
    int hours;

    double salary;

    do {
        cout << "Enter paycode (-1 to end):" << endl;
        cin >> paycode;

        switch (paycode) {
            case 2:
                cout << "Hourly worker selected\n";
                cout << "Enter the hourly salary: \n";
                cin >> salary;
                cout << "Enter the total hours worked: \n";
                cin >> hours;
                cout << "Worker's pay is: " << salary * hours << "\n";
                break;
        }    // End switch
    }while (paycode != -1);    // End do
}    //End function determineSalary

>Payroll companyPayroll();
Remove the parentheses. At the moment, you're telling the compiler that this is a function (it's supposed to be a variable).

I removed the smily and added the line numbers to make it a little easier to read the code.

Without actually compiling your program my guess is that the compiler doesn't like the open/close parentheses in line 16. And the keyword void in line 18 should be removed if it is trying to call that function.

Cool guys, I got it running, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.