|14| error: expected primary-expression before ‘EmployeeName’|

I've read through many forum posts here but am still unsure how to overcome this compiler error. It tells me that on line 14 of function main that it needs a primary-expression. However, I have the std::string right there!

Employee.h class specification file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  //Employee.h class specification file
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string>

class Employee
{
    private:    //private member variable & string objects
        int idNumber;
        std::string Empname;
        std::string Department;
        std::string Position;

    public:
        Employee(std::string, int, std::string, std::string);     //std::string, int, std::string, std::string
        Employee(std::string, int);
        Employee();

        void setEmpname(std::string);

        virtual ~Employee();
    protected:
};

#endif // EMPLOYEE_H




Employee.cpp class implementation file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//Employee.cpp class implementation file
#include "Employee.h"
#include <iostream>
#include <string>


Employee::Employee(std::string name, int id, std::string dprtmnt, std::string psition)    {

    //ctor
    Empname    = name;
    idNumber   = id;
    Department = dprtmnt;
    Position   = psition;
}

Employee::Employee(std::string name, int id)    {

    //ctor
    Empname    = name;
    idNumber   = id;
    Department = " ";
    Position   = " ";
}

//Default constructor, takes no arguments
Employee::Employee() {
    Empname    = " ";
    idNumber   = 0;
    Department = " ";
    Position   = " ";
}

//***********************************************
//This mutator function sets the employee       *
//name to the Empname class member variable.    *
//***********************************************
void setEmpname(std::string name) {
    std::cout << "Enter  employee name: ";
    getline(std::cin, name);
}



Employee::~Employee()
{
    //dtor
}



Function main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include "Employee.h"

int main()
{
    int employeeID;
    std::string EmployeeName;
    std::string Department;
    std::string Position;

    Employee worker(EmployeeName, employeeID, Department, Position);    //initialize worker object with variables, sent to constructor

    worker.setEmpname(std::string EmployeeName);

    return 0;
}
You haven't defined a member function setEmpname. At the moment you've defined a non-member function. Qualify it as void Employee::setEmpname in Employee.cpp
Additionally to what lastchance stated the syntax is wrong:

worker.setEmpname(std::string EmployeeName);
And make sure that in setEmpname you actually set the member variable Empname.

Actually, it's a bit unclear whether your intention is to pass it as a function parameter from main, or interrogate the user for it in setEmpname(). Maybe you should decide that first.
Thanks for your help everyone. Especially that last bit about actually setting the member variable to Empname. I was getting some strange garbage output and spent a decent amount of time figuring it out since everything read well to me (in English not C++).
Topic archived. No new replies allowed.