When I run this code, the name and salary variables are never set using the derived class "Programmer", even though it passes the variables through the parent class' constructor as suggested here. No errors are being given, but the name and salary variables just don't seem to get set for some reason.
#include <string>
#include <iostream>
using namespace std;
class Employee
{
public:
Employee();
Employee(string employee_name, double initial_salary);
void set_salary(double new_salary);
double get_salary() const;
string get_name() const;
private:
string name;
double salary;
};
Employee::Employee()
{
salary = 0;
}
Employee::Employee(string employee_name, double initial_salary)
{
name = employee_name;
salary = initial_salary;
}
void Employee::set_salary(double new_salary)
{
salary = new_salary;
}
double Employee::get_salary() const
{
return salary;
}
string Employee::get_name() const
{
return name;
}
class Programmer : public Employee {
public:
Programmer(string name, double salary);
string get_name();
private:
};
Programmer::Programmer(string pname, double psalary)
{
Employee(pname, psalary);
}
string Programmer::get_name()
{
return Employee::get_name();
}
int main() {
Programmer harry("Hacker, Harry", 10000);
cout << harry.get_name();
return 0;
}
This question wasn't the same as my problem from what I could tell. Though that one was much more complex.
It seems like a simple logic error, I just can't find it.