0

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>')

1
  • 1
    missing function call on cout<<emp3.getSalaried<<endl; Commented Jul 7, 2014 at 16:16

1 Answer 1

2

You forgot brackets after function call in getSalaried, should be

cout<<emp3.getSalaried()<<endl;

instead of

cout<<emp3.getSalaried<<endl;
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my God, i deserve downvotes from every user in stackoverflow. I am such an idiot. Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.