terminate called after throwing an instance of 'std::length_error'

After fixing a few other things that stopped my code from compiling I ended up getting the message

"terminate called after throwing an instance of 'std::length_error' what(): Basic_string::_S_create"

This is what I have. Ive searched other forums and found that the error can be linked to an empty string somewhere that is being accessed. However, I am not sure which one. Any help on figuring out how I should go about this would be greatly appreciated.
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  #include <iostream>

using namespace std;

class employee
{
public:
string firstname, designation;
double salary;
    // constructor
    employee (string fname, string desig, double sal);
    employee ();
    //accessors
    string get_first();
    string get_designation();
    double get_salary();
    //mutators
    void set_first(string fname);
    void set_designation(string desig);
    void set_salary(double sal);
    //overloaders
    void print(char c)
    {
        cout << "printing: " << c << endl;
    }
    void read (char charact)
    {
        cout << "Reading: " << endl;
        cin >> charact;
    }
    void compare(employee obj1, employee obj2)
    {
       if (obj1.salary == obj2.salary)
            cout <<"Employee salaries are the same"<<endl;
       else
            cout <<"Employee salaries are different"<<endl;
    }
    double add(employee obj3, double num1)
    {
        obj3.salary = obj3.salary + num1;
        return obj3.salary;
    }
    string addname(employee obj4, string name1)
    {
        obj4.firstname = obj4.firstname + " " + name1;
    }
};
    // Constructor
    employee::employee (string fname, string desig, double sal)
    {
        firstname = fname;
        designation = desig;
        salary = sal;
    }
    employee::employee ()
    {
     // do nothing
    }
class consultant: public employee
{
    int tenure1;
public:
    // constructor
    consultant (int tenure);
    consultant ();
    // modifiers and accessors
    int get_tenure();
    void set_tenture(int tenure);
};
    // Constructor
    consultant::consultant (int tenure) : employee(firstname, designation,salary)
    {
        tenure = tenure1;
    }
    consultant::consultant () : employee(firstname,designation,salary)
    {
     // do nothing
    }

int main()
{
    employee object1("Name1","Location1",5000.00);
    consultant object;
    employee object2;
    employee object3;
    //Modifier input for employee 2
    object2.firstname = "Name2";
    object2.designation = "Location2";
    object2.salary = 1000.00;
    //User input for employee 3
    cout <<"Enter the information for the third employee. (name/designation/salary)\n " ;
    cin >> object3.firstname >> object3.designation >> object3.salary;
    // Adding last names
    object1.addname(object1,"LastName1");
    object2.addname(object2,"Lastname2");
    object3.addname(object3,"lastname3");
    // salary changes
    object1.add(object1, 500.00);
    object2.add(object2, 1300.00);
    object3.add(object3,800.00);
    // Printing details.
    cout<<"Employee 1 has name "<<object1.firstname<<" designation "<<object1.designation<< endl;
    cout<<" and a salary of $" <<object1.salary<<endl;
    cout<<"Employee 2 has name "<<object2.firstname<<" designation "<<object2.designation<< endl;
    cout<<" and a salary of $" <<object2.salary<<endl;
    cout<<"Employee 3 has name "<<object3.firstname<<" designation "<<object3.designation<< endl;
    cout<<" and a salary of $" <<object3.salary<<endl;
    cout<<"Consultant1 has name "<<object.firstname<<" designation "<<object.designation<< endl;
    cout<<" and a salary of $" <<object.salary<<endl;
return 0;
}
// Definitions
// Employee class

string employee::get_first()
{
    return firstname;
}
string employee::get_designation()
{
    return designation;
}
double employee::get_salary()
{
    return salary;
}
void employee::set_first(string fname)
{
    firstname = fname;
}
void employee::set_designation(string desig)
{
    designation = desig;
}
void employee::set_salary(double sal)
{
    salary = sal;
}
// Consultant class
void consultant::set_tenture(int tenure)
{
    tenure1 =tenure;
}
Topic archived. No new replies allowed.