0

The assignment Im working on involves creating a database of employees and outputing some basic information about them. Im having trouble in my header class files. the error i get is "error: passing 'const Owner' as 'this' argument of 'double Employee::getSalary()' discards qualifiers"

I think its the way im passing the mySalary into the display but im a bit stumped on how to get around this without having to create a calculate_salary() function and calculate the salary in the driver program.

#include <iostream>

#ifndef EMPLOYEE
#define EMPLOYEE

class Employee
{
 public:
  Employee(long id = 0, string last = "", string first = "",char EmpClass = ' ', double salary = 0);

  virtual void display(ostream & out)const;
  double getSalary();

 private:
  long myId;
  string myLastName,myFirstName;
  char myEmpClass;
  double mySalary;

};


inline Employee::Employee(long id, string last, string first, char EmpClass, double salary)
  : myId(id), myLastName(last), myFirstName(first),myEmpClass(EmpClass), mySalary(salary)
{ }

inline void Employee::display(ostream & out)const
{
  out << myId << endl << myLastName << ", "
      << myFirstName << endl << myEmpClass << endl
      << "$" << mySalary << endl;
}

inline ostream & operator<<(ostream & out, const Employee & emp)
{
  emp.display(out);
  return out;
}

double Employee::getSalary()
{
  return this->mySalary;
}

#endif
#include "Employee.h"

#ifndef OWNER
#define OWNER

class Owner : public Employee
{
 public:
   Owner (long id = 0, string last = "",string first = "", char EmpClass = ' ', double salary = 0, double profit = 0);

  virtual void display(ostream & out)const;

 private:
  double myProfit;
};

inline Owner::Owner(long id, string last, string first, char EmpClass, double salary, double profit)
: Employee(id, last, first, EmpClass, salary), myProfit(profit)
{ }


inline void Owner::display(ostream & out)const
{
  Employee::display(out);
  out << "This month's pay: $" << getSalary() + myProfit*.6 << endl;
}



#endif

these are just the 2 header files(employee is the base class). Im pretty sure that my driver file is fine as it just creates and cout the objects, but if you need to see it then ill throw it up there.

Thanks again in advance

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
1

you can only put inline executable code in a header file -- mark that function as inline, like you did the other functions.

It is customary to put inline functions inside the class definition, not outside of it.

#include <iostream>

#ifndef EMPLOYEE
#define EMPLOYEE

class Employee
{
 public:
  Employee(long id = 0, string last = "", string first = "",char EmpClass = ' ', double salary = 0) : myId(id), myLastName(last), myFirstName(first),myEmpClass(EmpClass), mySalary(salary) {}

  virtual void display(ostream & out)const
  {
     out << myId << endl << myLastName << ", "
      << myFirstName << endl << myEmpClass << endl
      << "$" << mySalary << endl;
  }
  double getSalary() {return mySalary;}

 private:
  long myId;
  string myLastName,myFirstName;
  char myEmpClass;
  double mySalary;

};




inline ostream & operator<<(ostream & out, const Employee & emp)
{
  emp.display(out);
  return out;
}


#endif

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.