error iostream

This is a discussion on error iostream within the C++ Programming forums, part of the General Programming Boards category; This code is giving me a odd error dont know why.It says 42 c:\dev-c_~1\employee.cpp no match for `ostream & << ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    error iostream

    This code is giving me a odd error dont know why.It says 42 c:\dev-c_~1\employee.cpp
    no match for `ostream & << {unknown type}'

    77 c:\dev-c_~1\include\g__~1\iostream.h
    candidates are: class ostream & ostream:perator <<(char)

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    class Employee{
          int age;
          int yearsOfService;
          int Salary;
          public:
                 Employee();
                 int getAge();
                 int getYears();
                 int getSalary();
    
                 void setAge(int);
                 void setYears(int);
                 void setSalary(int);
    
                 ~Employee();
    };
    
    int Employee::getAge(){ return age; }
    int Employee::getYears(){ return yearsOfService; }
    int Employee::getSalary(){ return Salary; }
    
    void Employee::setAge(int num){ age = num; }
    void Employee::setYears(int num){ yearsOfService = num; }
    void Employee::setSalary( int num ){ Salary = num; }
    
    
    
    
    int main()
    {
     Employee t;
    
     t.setAge(18);
     t.setYears(2);
     t.setSalary(2000);
    
     cout << "Employee's age " << t.getAge <<", Years of service " << t.getYears
          << " and Salary " << t.getSalary << endl;
    
          system("PAUSE");
          return 0;
    }
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    CHANGE
    cout << "Employee's age " << t.getAge <<", Years of service " << t.getYears
    << " and Salary " << t.getSalary << endl;
    TO
    cout << "Employee's age " << t.getAge() <<", Years of service " << t.getYears()
    << " and Salary " << t.getSalary() << endl;

    and another problem is that you haven't implemented Employee() or ~Employee()

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    That's correct, because getAge(), getYears(), ... are functions that return values which will be printed, so you have to call like this cout << getYears()
    none...

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21