Hey guys, I'm getting a few errors I can't seem to figure out solutions for:

(SalesEmployee Line 21) error C2248: 'SalariedEmployee::salary' : cannot access private member declared in class 'SalariedEmployee'

(SalesEmployee Line 17) error C2664: 'SalariedEmployee:: SalariedEmployee(const SalariedEmployee &)' : cannot convert parameter 1 from 'std::string' to 'const SalariedEmployee &'

I've been staring at it for a while now but I'm getting nothing unfortunately...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class Employee
{
	private:
		string name;

	public:
		Employee(string n) : name(n) { }

		friend	ostream& operator<<(ostream& outStrm, Employee& e)
		{
			outStrm << e.name << endl;
			return outStrm;
		}  
};

#endif
#ifndef _SALARIEDEMPLOYEE_
#define _SALARIEDEMPLOYEE_

#include <string>
#include <iostream>
#include "Employee.h"
using namespace std;

class SalariedEmployee : public Employee
{
	private:
		double salary;

	public: 
		SalariedEmployee(string name, double s) : Employee(name), salary(s) { }

		friend	ostream& operator<<(ostream& outStrm, SalariedEmployee& e)
		{
			outStrm << (Employee &)e << "\n Wage: " << e.salary << endl;
			return outStrm;
		}
};

#endif
#ifndef _SALESEMPLOYEE_
#define _SALESEMPLOYEE_

#include <string>
#include <iostream>
#include "Employee.h"
#include "SalariedEmployee.h"
using namespace std;

class SalesEmployee : public SalariedEmployee
{
	private:
		double commission;
		double sales;

	public:
/*Error*/		SalesEmployee(string name, double sal, double com, double totsales) : SalariedEmployee(name), commission(com), sales(totsales) { }

		friend ostream& operator<<(ostream& outStrm, SalesEmployee& e)
		{
/*Error*/	outStrm << (SalariedEmployee &)e << "\n Salary: " << e.salary << "\n Wage: " << e.commission << "\n Sales: " << e.sales << endl;
			return outStrm;
		}
};

#endif
#ifndef _WAGEDEMPLOYEE_
#define _WAGEDEMPLOYEE_

#include <string>
#include <iostream>
#include "Employee.h"
using namespace std;

class WagedEmployee : public Employee
{
	private:
		double wage;
		double hours;

	public: 
		WagedEmployee(string name, double w, double h) : Employee(name), wage(w), hours(h) { }

		friend	ostream& operator<<(ostream& outStrm, WagedEmployee& e)
		{
			outStrm << (Employee &)e << "\n Wage: " << e.wage << "\n Hours: " << e.hours << endl;
			return outStrm;
		}
};

#endif
#include <iostream> 
#include <string>
#include "Employee.h"
#include "SalariedEmployee.h"
#include "SalesEmployee.h"
#include "WagedEmployee.h"
using namespace std;

void prompt(char* message, string& variable);
void prompt(char* message, double& number);

int main()
{
	while (1)
	{
		cout << endl;
		cout << "1. Waged Employee" << endl;
		cout << "2. Salaried Employee" << endl;
		cout << "3. Sales Employee" << endl;
		cout << "4. Exit" << endl << endl;
		cout << "Choose an Employee or an Action: ";

		char c;
		cin >> c;
		cin.ignore();
		string name;				// variables used by all employee types

		switch(c)
		{
			case '1' :
				{
					double	wage;
					double	hours;
					prompt("Name", name);
					prompt("Wage", wage);
					prompt("Hours", hours);
					WagedEmployee* we = new WagedEmployee(name, wage, hours);
					cout << *we << endl;
					break;
				}

			case '2' :
				{
					double	salary;
					prompt("Name", name);
					prompt("Salary", salary);
					SalariedEmployee* se = new SalariedEmployee(name, salary);
					cout << *se << endl;
					break;
				}

			case '3' :
				{
					double	salary;
					double	commission;
					double	sales;
					prompt("Name", name);
					prompt("Salary", salary);
					prompt("Commission", commission);
					prompt("Sales", sales);
					SalesEmployee* se = new SalesEmployee(name, salary, commission, sales);
					cout << *se << endl;
					break;
				}

			case '4' :
				exit(0);
		}
	}

	return 0;
}

void prompt(char* message, string& variable)
{
	cout << message << ": ";
	getline(cin, variable);
}

void prompt(char* message, double& number)
{
	cout << message << ": ";
	cin >> number;
	cin.get();		// discard \n following number
}
SalesEmployee Line 21) error C2248: 'SalariedEmployee::salary' : cannot access private member declared in class 'SalariedEmployee'

For this error:
make a getSalary() method int the SalariedEmployee class that returns the slaray as the private members are accessible only in the class they are declared so:
In the SalareidEmployee class do as follows:

   public double getSalary() 
   {
       return salary;
   }

And then use this method to access the value of salary in the SalesEmployee class:
Then in line 22 in SalesEmployee, instead of e.salary write e.getSalary()

SalesEmployee Line 17) error C2664: 'SalariedEmployee:: SalariedEmployee(const SalariedEmployee &)' : cannot convert parameter 1 from 'std::string' to 'const SalariedEmployee &'   

And for this error in line 18:
instead of SalariedEmployee(name) write the following: SalariedEmployee(name, sal)

I hope this would help
Cheers
Raman

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I think you should make all those data members under the "protected" scope instead of "private", that would solve all your problems.

The string error is fixed thanks, but im getting an undeclared identifier error for the first solution

This question has already been answered. Start a new discussion instead.