0

I'm having problem getting some separate compilation done. It's simple, but I can't figure out this error.

I'm getting these exceptions:

> 36 C:\Cpp\P6\employee.cpp expected `)' before ',' token 36
> C:\Cpp\P6\employee.cpp expectedinit-declarator before ')' token  36
> C:\Cpp\P6\employee.cpp expected `,' or `;' before ')' token  42
> C:\Cpp\P6\employee.cpp expected `)' before ',' token  42
> C:\Cpp\P6\employee.cpp expected init-declarator before ')' token  42
> C:\Cpp\P6\employee.cpp expected `,' or `;' before ')' token

for this code:

    /*line 36*/ Employee::Employee(n, id) { //constructor for name and ID

                            setName(n);
                            setID(id);
    };

   /*line 42*/ Employee::Employee(id, d, p, n) {//constructor for all member variables

                        setID(id);
                        setDept(d);
                        setPos(p);
                        setName(n);
    };

the header file looks like(they're public):

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

Any help as to what those errors mean or how I can fix them?

William
  • 1,517
  • 1
  • 12
  • 26

1 Answers1

4

You always have to have a type preceding variable name. You have it in declaration but not in definition. Something like the following should fix it:

Employee::Employee(std::string n, int id) { //constructor for name and ID

                            setName(n);
                            setID(id);
    };

Same goes for the second Employee constructor definition.

Also, it is better to pass std::string by constant reference rather than by value. And... you avatar is rotated 45 degrees left.

  • That took care of that. But now, the compiler complains about my accessors/mutators being unreferenced... – William Apr 28 '11 at 20:58
  • Since this is homework and due in an hour I'm just going to take what I have. I have it working by just assigning those variables to those parameters. I'll figure out the getters and setters later. Thanks for your help. – William Apr 28 '11 at 20:59
  • Undefined references? What exactly compiler says? It is funny but after long years of working with compilers you understand their error messages much better than people trying to describe it. Hehe –  Apr 28 '11 at 21:00
  • Derp - undefined references yes. Sorry I'm bouncing back and forth between a lot of things right now haha. – William Apr 28 '11 at 21:11