Problem With My Class

This is my first time writing a header class file and I'm stuck.
Here's my code. Any help is greatly appreciated. :) Thanks!
Header 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
49
50
51
52
53
54
  #ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <cstring>
using namespace std;
class Employee
{
private:
   char *Name;
   int IdNum;
   char *Dpt;
   char *Pos;
public:
    Employee (char *n, int id, char *dep, char *title ){
     Name = new char[strlen(n)+1];
     strcpy(Name,n);
     id = IdNum;
     Dpt = new char[strlen(dep)+1];
     strcpy(Dpt,dep);
     Pos = new char[strlen(title)+1];
     strcpy(Pos,title);
    }
    ~Employee()
    {
        delete [] Name;
        delete [] Dpt;
        delete [] Pos;
    }
    void setName(char *N){
        strcpy(Name,N);
    }
    void setIdNum(int X){
     IdNum = X;   
    }
    void setDpt(char *D){
      strcpy(Dpt,D);   
    }
    void setPos(char *P){
     strcpy(Pos,P);   
    }
    char getName()const {
        return *Name;
    }
    int getIdNum()const{
        return IdNum;
    }
    char getDpt()const{
        return *Dpt;
    }
    char getPos() const {
     return *Pos;   
    }
    
};
#endif 



Main 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
#include <iostream>
#include <cstdlib>
#include "Employee.h"
using namespace std;
int main (){
    Employee One;
    Employee Two;
    Employee Three;
    //Set Info
    One.setName("Susan Meyers");
    One.setIdNum(47899);
    One.setDpt("Accounting");
    One.setPos("Vice President");
    
    Two.setName("Mark Jones");
    Two.setIdNum(39119);
    Two.setDpt("IT");
    Two.setPos("Programmer");
    
    Three.setName("Joy Rogers");
    Three.setIdNum(81774);
    Three.setDpt("Manufacturing");
    Three.setPos("Engineer");
    // Get Info
    One.getName();
    One.getIdNum();
    One.getDpt();
    One.getPos();
    
    Two.getName();
    Two.getIdNum();
    Two.getDpt();
    Two.getPos();
    
    Three.getName();
    Three.getIdNum();
    Three.getDpt();
    Three.getPos();
    
    return 0;
}
Also, here are my errors:

In file included from main.cpp:3:
Employee.h:54:7: warning: no newline at end of file
main.cpp: In function `int main()':
main.cpp:6: error: no matching function for call to `Employee::Employee()'
Employee.h:6: note: candidates are: Employee::Employee(const Employee&)
Employee.h:13: note: Employee::Employee(char*, int, char*, char*)
main.cpp:7: error: no matching function for call to `Employee::Employee()'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
Employee.h:6: note: candidates are: Employee::Employee(const Employee&)
Employee.h:13: note: Employee::Employee(char*, int, char*, char*)
main.cpp:8: error: no matching function for call to `Employee::Employee()'
Employee.h:6: note: candidates are: Employee::Employee(const Employee&)
Employee.h:13: note:Employee::Employee(char*, int, char*, char*)
main.cpp:41:2: warning: no newline at end of file
main.cpp:6: error: no matching function for call to `Employee::Employee()'
1
2
Employee One;
// ... 


you declared another constructor which causes the default constructor to be deleted, you should implement again the default constructor ( the one w/ no args ) to be able to instantiate an object using this style, or use your already existing overloaded constructor

well almost all of the error came up because of this
Thanks! My Program is running now but my output is nonsense. Here's my edited code:

Header 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
49
50
51
52
53
54
55
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <cstring>
using namespace std;
class Employee
{
private:
   char *Name;
   int IdNum;
   char *Dpt;
   char *Pos;
public:
    Employee();
    Employee (char *n, int id, char *dep, char *title ){
     Name = new char[strlen(n)+1];
     strcpy(Name,n);
     id = IdNum;
     Dpt = new char[strlen(dep)+1];
     strcpy(Dpt,dep);
     Pos = new char[strlen(title)+1];
     strcpy(Pos,title);
    }
    ~Employee()
    {
        delete [] Name;
        delete [] Dpt;
        delete [] Pos;
    }
    void setName(char *N){
        strcpy(Name,N);
    }
    void setIdNum(int X){
     IdNum = X;   
    }
    void setDpt(char *D){
      strcpy(Dpt,D);   
    }
    void setPos(char *P){
     strcpy(Pos,P);   
    }
    char getName()const {
        cout << *Name;
    }
    int getIdNum()const{
        cout << IdNum;
    }
    char getDpt()const{
        cout << *Dpt;
    }
    char getPos() const {
     cout << *Pos;   
    }
    
};
#endif 


Main:

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
#include <iostream>
#include <cstdlib>
#include "Employee.h"
using namespace std;
int main (){
    Employee One ("Susan Meyers", 47899, "Accounting", "Vice President");
    Employee Two ("Mark Jones", 39119, "IT", "Programmer");
    Employee Three ("Joy Rogers", 81774, "Manufacturing", "Engineer");
   
    // Get Info
    One.getName();
    One.getIdNum();
    One.getDpt();
    One.getPos();
    
    Two.getName();
    Two.getIdNum();
    Two.getDpt();
    Two.getPos();
    
    Three.getName();
    Three.getIdNum();
    Three.getDpt();
    Three.getPos();
    
    return 0;
}


Output:
S2675740AVM1627417680IPJ2675740ME
Nevermind! I figured it out. Thanks for the pointer. Here's my final code:

Header:

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
49
50
51
52
53
54
55
56
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <cstring>
using namespace std;
class Employee
{
private:
   char *Name;
   int IdNum;
   char *Dpt;
   char *Pos;
public:
    Employee();
    Employee (char *n, int id, char *dep, char *title ){
     Name = new char[strlen(n)+1];
     strcpy(Name,n);
     id = IdNum;
     Dpt = new char[strlen(dep)+1];
     strcpy(Dpt,dep);
     Pos = new char[strlen(title)+1];
     strcpy(Pos,title);
    }
    ~Employee()
    {
        delete [] Name;
        delete [] Dpt;
        delete [] Pos;
    }
    void setName(char *N){
        strcpy(Name,N);
    }
    void setIdNum(int X){
     IdNum = X;   
    }
    void setDpt(char *D){
      strcpy(Dpt,D);   
    }
    void setPos(char *P){
     strcpy(Pos,P);   
    }
    char getName()const {
        cout << "Name: " <<Name << endl ;
    }
    int getIdNum()const{
        cout << "Id Number: " << IdNum << endl ;
    }
    char getDpt()const{
        cout << "Department: " << Dpt << endl ;
    }
    char getPos() const {
     cout << "Position: " << Pos << endl ;
     cout << endl;
    }
    
};
#endif 


Main:
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
#include <iostream>
#include <cstdlib>
#include "Employee.h"
using namespace std;
int main (){
    Employee One ("Susan Meyers", 47899, "Accounting", "Vice President");
    Employee Two ("Mark Jones", 39119, "IT", "Programmer");
    Employee Three ("Joy Rogers", 81774, "Manufacturing", "Engineer");
   
    // Get Info
    One.getName();
    One.getIdNum();
    One.getDpt();
    One.getPos();
    
    Two.getName();
    Two.getIdNum();
    Two.getDpt();
    Two.getPos();
    
    Three.getName();
    Three.getIdNum();
    Three.getDpt();
    Three.getPos();
    
    return 0;
}
Topic archived. No new replies allowed.