473,668 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header file and code not working

9 New Member
I'm getting like, 60 some errors and I don't know what I'm doing wrong. Everything seems to be assembled like my last assignment but it doesn't work this time. Any help on what I'm doing wrong would be appreciated.

Employee.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef EMPLOYEE_H
  2. #define EMPLOYEE_H
  3. #include <string>
  4.  
  5. class Employee
  6. {
  7.     private:
  8.         string first_name;
  9.         string last_name;
  10.         string employee_id;
  11.     public:
  12.         Employee();
  13.         Employee(string, string, string);
  14.         void set_first_name(string);
  15.         void set_last_name(string);
  16.         void set_employee_id(string);
  17.         string get_first_name();
  18.         string get_last_name();
  19.         string get_employee_id();
  20.         void display_e();
  21. };
  22.  
  23. #endif
Employee.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Employee::Employee();
  7. {    first_name = "unknown";
  8.     last_name = "unknown";
  9.     employee_id = "EEEEE"; }
  10.  
  11. Employee::Employee(string first_name, string last_name, string employee_id);
  12. {    set_first_name(first_name);
  13.     set_last_name(last_name);
  14.     set_employee_id(employee_id); }
  15.  
  16. void Employee::set_first_name(string first);
  17. {    first_name = first; }
  18.  
  19. void Employee::set_last_name(string last);
  20. {    last_name = last; }
  21.  
  22. void Employee::set_employee_id(string id);
  23. {    employee_id = id; }
  24.  
  25. string Employee::get_first_name();
  26. {    return first_name; }
  27.  
  28. string Employee::get_last_name();
  29. {    return last_name; }
  30.  
  31. string Employee::get_employee_id();
  32. {    return employee_id; }
  33.  
  34. void Employee::display_e();
  35. {    cout << "First name: " << first_name << endl;
  36.     cout << "Last name: " << last_name << endl;
  37.     cout << "Employee ID: " << employee_id << endl; }
Lab09.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     Employee emp("John", "Doe", "E1234");
  9.     emp.display_e();
  10.  
  11.     return 0;
  12. }
Nov 15 '07 #1
6 5469
gpraghuram
1,275 Recognized Expert Top Contributor
I saw one problem....
using namespace std; is missing in the employee.h file.
i will post again if i find other errors.

raghuram
Nov 16 '07 #2
jumpman17
9 New Member
Hmm, I didn't think you needed that in the header but it cut my errors from 60 some to 18.

Any idea what these mean?

Expand|Select|Wrap|Line Numbers
  1. employee.cpp(6) : error C2761: '{ctor}' : member function redeclaration not allowed
  2. employee.cpp(7) : error C2447: '{' : missing function header (old-style formal list?)
  3. employee.cpp(11) : error C2761: '{ctor}' : member function redeclaration not allowed
  4. employee.cpp(12) : error C2447: '{' : missing function header (old-style formal list?)
  5. employee.cpp(16) : error C2761: 'void Employee::set_first_name(std::string)' : member function redeclaration not allowed
  6. employee.cpp(17) : error C2447: '{' : missing function header (old-style formal list?)
  7. employee.cpp(19) : error C2761: 'void Employee::set_last_name(std::string)' : member function redeclaration not allowed
  8. employee.cpp(20) : error C2447: '{' : missing function header (old-style formal list?)
  9. employee.cpp(22) : error C2761: 'void Employee::set_employee_id(std::string)' : member function redeclaration not allowed
  10. employee.cpp(23) : error C2447: '{' : missing function header (old-style formal list?)
  11. employee.cpp(25) : error C2761: 'std::string Employee::get_first_name(void)' : member function redeclaration not allowed
  12. employee.cpp(26) : error C2447: '{' : missing function header (old-style formal list?)
  13. employee.cpp(28) : error C2761: 'std::string Employee::get_last_name(void)' : member function redeclaration not allowed
  14. employee.cpp(29) : error C2447: '{' : missing function header (old-style formal list?)
  15. employee.cpp(31) : error C2761: 'std::string Employee::get_employee_id(void)' : member function redeclaration not allowed
  16. employee.cpp(32) : error C2447: '{' : missing function header (old-style formal list?)
  17. employee.cpp(34) : error C2761: 'void Employee::display_e(void)' : member function redeclaration not allowed
  18. employee.cpp(35) : error C2447: '{' : missing function header (old-style formal list?)
Nov 16 '07 #3
gpraghuram
1,275 Recognized Expert Top Contributor
The issue is in the Employee.cpp file is the ; at the end of every function.
I have corrected it...echeck it
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Employee::Employee()
  7. {   first_name = "unknown";
  8.     last_name = "unknown";
  9.     employee_id = "EEEEE"; }
  10.  
  11. Employee::Employee(string first_name, string last_name, string employee_id)
  12. {   set_first_name(first_name);
  13.     set_last_name(last_name);
  14.     set_employee_id(employee_id); }
  15.  
  16. void Employee::set_first_name(string first)
  17. {   first_name = first; }
  18.  
  19. void Employee::set_last_name(string last)
  20. {   last_name = last; }
  21.  
  22. void Employee::set_employee_id(string id)
  23. {   employee_id = id; }
  24.  
  25. string Employee::get_first_name()
  26. {   return first_name; }
  27.  
  28. string Employee::get_last_name()
  29. {   return last_name; }
  30.  
  31. string Employee::get_employee_id()
  32. {   return employee_id; }
  33.  
  34. void Employee::display_e() //dont add a ; here
  35. {   cout << "First name: " << first_name << endl;
  36.     cout << "Last name: " << last_name << endl;
  37.     cout << "Employee ID: " << employee_id << endl; }
  38.  
  39.  

Raghuram
Nov 16 '07 #4
jumpman17
9 New Member
Thank you so much. That fixed all the errors. Now I can move on and code the rest of the program.
Nov 16 '07 #5
jumpman17
9 New Member
Alright, I'm trying to add in a child class and I'm sure that the errors I'm getting have to do with me not calling the variables right or something. It started out at 15 errors and I've got it down to 6 and now I'm stuck.

Employee.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef EMPLOYEE_H
  2. #define EMPLOYEE_H
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Employee
  7. {
  8.     private:
  9.         string first_name;
  10.         string last_name;
  11.         string employee_id;
  12.     public:
  13.         Employee();
  14.         Employee(string, string, string);
  15.         void set_first_name(string);
  16.         void set_last_name(string);
  17.         void set_employee_id(string);
  18.         string get_first_name();
  19.         string get_last_name();
  20.         string get_employee_id();
  21.         void display_e();
  22. };
  23.  
  24. class StaffEmployee:public Employee
  25. {
  26.     private:
  27.         int annual_salary;
  28.         bool outsourced;
  29.         int tax_bracket;
  30.     public:
  31.         StaffEmployee();
  32.         StaffEmployee(string, string, string, int, bool, int);
  33.         void set_annual_salary(int);
  34.         void set_outsourced(bool);
  35.         void set_tax_bracket(int);
  36.         void display_s();
  37. };
  38.  
  39. #endif
Employee.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Employee::Employee()
  7. {    first_name = "unknown";
  8.     last_name = "unknown";
  9.     employee_id = "EEEEE"; }
  10.  
  11. Employee::Employee(string first_name, string last_name, string employee_id)
  12. {    set_first_name(first_name);
  13.     set_last_name(last_name);
  14.     set_employee_id(employee_id); }
  15.  
  16. void Employee::set_first_name(string first)
  17. {    first_name = first; }
  18.  
  19. void Employee::set_last_name(string last)
  20. {    last_name = last; }
  21.  
  22. void Employee::set_employee_id(string id)
  23. {    employee_id = id; }
  24.  
  25. string Employee::get_first_name()
  26. {    return first_name; }
  27.  
  28. string Employee::get_last_name()
  29. {    return last_name; }
  30.  
  31. string Employee::get_employee_id()
  32. {    return employee_id; }
  33.  
  34. void Employee::display_e()
  35. {    cout << "First name: " << first_name << endl;
  36.     cout << "Last name: " << last_name << endl;
  37.     cout << "Employee ID: " << employee_id << endl; }
  38.  
  39. StaffEmployee::StaffEmployee()
  40. {    annual_salary = 0;
  41.     outsourced = false;
  42.     tax_bracket = 1; }
  43.  
  44. StaffEmployee::StaffEmployee(string first_name, string last_name, string employee_id, int annual_salary; bool outsourced, int tax_bracket)
  45. {    set_first_name(first_name);
  46.     set_last_name(last_name);
  47.     set_employee_id(employee_id);
  48.     set_annual_salary(annual_salary);
  49.     set_outsourced(outsourced);
  50.     set_tax_bracket(tax_bracket); }
  51.  
  52. void StaffEmployee::set_annual_salary(int annual)
  53. {    annual_salary = annual; }
  54.  
  55. void StaffEmployee::set_outsourced(bool out)
  56. {    outsourced = out; }
  57.  
  58. void StaffEmployee::set_tax_bracket(int tax)
  59. {    tax_bracket = tax; }
  60.  
  61. void StaffEmployee::display_s()
  62. {    cout << "First name: " << get_first_name() << endl;
  63.     cout << "Last name: " << get_last_name() << endl;
  64.     cout << "Employee ID: " << get_employee_id() << endl;
  65.     cout << "Annual salary: " << annual_salary << endl;
  66.     cout << "Outsourced: " << outsourced << endl;
  67.     cout << "Tax bracket: " << tax_bracket << endl; }
Lab09.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     Employee emp("John", "Doe", "E1234");
  9.     emp.display_e();
  10.  
  11.     StaffEmployee staff("Natalie", "Simons", "E3345", 56000, true, 3);
  12.     staff.display_s();
  13.  
  14.     return 0;
Expand|Select|Wrap|Line Numbers
  1. employee.cpp(44) : error C2143: syntax error : missing ')' before ';'
  2. employee.cpp(44) : error C2761: '{ctor}' : member function redeclaration not allowed
  3. employee.cpp(44) : error C2062: type 'int' unexpected
  4. employee.cpp(44) : error C2059: syntax error : ')'
  5. employee.cpp(45) : error C2143: syntax error : missing ';' before '{'
  6. employee.cpp(45) : error C2447: '{' : missing function header (old-style formal list?)
Nov 16 '07 #6
oler1s
671 Recognized Expert Contributor
Why were you stuck? If you look at the errors, it looks like there is a problem around line 44. So you start reading a couple of lines back (line 42, say), and look closely for syntax errors. Things like a missing semicolon, misplaced brace, etc.

I found that you had a semicolon after int annual_salary, when it should be a comma.
Nov 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3932
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
9
4040
by: chat | last post by:
Hi, every body. I have 3 files like this: -------------------------------------------------------- file name : header.h #ifndef TEST_H #define TEST_H int a=1; double b=0.5;
0
1079
by: srikar | last post by:
Hi all, I am working on porting of code in C++, I am having the following problem. In my code The following structure has been defined static struct rwtable { /* reserved word table */ char * rw_name; /* representation */ int rw_yylex; /* yylex() value */ } rwtable = { /* sorted */ # include "y_token_names.h"
7
2245
by: The Cool Giraffe | last post by:
Please note that i do intend to use a header file. However, i'm not sure if it's really needed or just a convention. Suppose we have the following two files. // Something.h class Something { private: int number; public: Something ();
14
11732
by: Jess | last post by:
Hello, I was told that if I have a template class or template function, then the definitions must be put into the header file where I put the declarations. On the other hand, it is generally good to put source code and declaration into separate files (.h head filer and .cpp source file). What can I do to template functions/classes? Do I have to put them all into one header file? Thanks,
1
2787
by: Swapnil Kale | last post by:
Hi, I'm working on a Migration project (Forte to JAVA). The forte client had a C++ dll which used to call one more FORTE dll for a complex database calculations. Now all the forte code has been migrated to JAVA except this piece of code where C++ dll calls Forte DLL.
1
1486
by: araman | last post by:
I have a header file that gets included with my main pages. I moved a file to a different folder that has the header.asp fie in it but when I go to that page the header does not get included.It works in its original folder so the code on the page is correct. Am I missing something?
4
5148
by: quophyie | last post by:
Hi guys I''m a new C++ programmer and I am having a few problems with some structs that I have defined in my header file and want to use in my CPP file. The struct called "deck" is defined in a file called "Cards.h". In the corresponding CPP file called "Cards.cpp" when I try to use the struct "deck", I get a lot of errors from the compiler as displayed in my compiler errors below. I have tried all manner of things including defing variables...
8
4584
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
1359
by: adikat | last post by:
I am trying to set up a webpage where a user can download a .PNG image. The download works fine via computer and browser but it doesn't work when I try to download it via a browser on my Android phone. It tries to download but then give me 'download unsuccessful' it doesn't give any other errors. Here is the PHP code that I am using: header('Content-Description: File Transfer'); header('Content-Type: image/png');...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8583
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2791
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.