Reputation: 1389
I created this code, and I am facing an error in the final cout
in the main
. This error only appears when I am trying to print something from class Manager
. I searched Stackoverflow for the same error and I have to say that many have this error but mostly on templates so thats why I can't adopt any of these solutions in my case.
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
//Base Class
class Employee {
private:
string name;
double pay;
public:
Employee()
{
name ="";
pay = 0;
}
Employee(string empName, double payRate){
name = empName;
pay = payRate;
}
string getName(){
return name;
}
void setName(string empName){
name = empName;
}
double getPay()
{
return pay;
}
void setPay(double payRate)
{
pay = payRate;
}
string toString()
{
stringstream stm;
stm <<name<<": "<< pay;
return stm.str();
}
};
//derived class
class Manager : public Employee
{
private:
bool salaried;
public:
Manager(string name, double payRate, bool isSalaried)
: Employee(name, payRate)
{
salaried = isSalaried;
}
bool getSalaried()
{
return salaried;
}
};
int main()
{
Employee emp1("Jane",3500);
Employee emp2("Bill",3200);
cout<<emp1.toString()<<endl;
cout<<emp2.toString()<<endl;
Manager emp3("Bob",1500,true);
cout<<emp3.toString()<<endl;
cout<<emp3.getSalaried<<endl;
return 0;
}
Error:
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and '<unresolved overloaded function type>')
Upvotes: 0
Views: 35
Reputation: 5345
You forgot brackets after function call in getSalaried
, should be
cout<<emp3.getSalaried()<<endl;
instead of
cout<<emp3.getSalaried<<endl;
Upvotes: 2