Results 1 to 6 of 6

Thread: Hye i am still getting around 31 errors on this Simple Class! whats up?

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Red face

    Hello everyone again, i still can't figure out this problem!
    i am getting these compiler errors!


    here is my .hpp file with the class interface:

    Code:
    #include <iostream.h>
    
    class Employee
    {
     public:
            void SetAge(int EAge);                      
            void SetyearsOfService(int yOf);  
             void SetSalary(int Money);             
    
             int GetAge();                             
             int GetyearsOfservice();         
             int GetSalary();                        
    
    
     private:
             int age;
             int yearsOfservice;
             int Salary;
    
     };
    here is the .cpp file with the implemnation of the class methods:
    Code:
    #include "Employee.hpp"
    
    //function implamenation (can't spell) :P
            void Cat::SetAge(int EAge)
            {
             age = EAge;
            }
                                  //
            void Cat::SetyearsOfService(int yOf)
             {
             yearsOfservice = yOf;  //
             }
             void Cat::SetSalary(int Money)             //
             {
             Salary = Money;
             }
    
             int Cat::GetAge()
             {
             return age;
             }                             //
    
             int Cat::GetyearsOfservice()         //
             {
             return yearsOfservice;
             }
    
             int Cat::GetSalary()
             {
             return Salary;
             }
    
    int main() {
    
    Employee Cory;
    Cory.SetAge(15);
    Cory.SetSalary(100000);
    Cory.GetyearsOfservice(4);
    
    cout << Cory.GetAge << endl;
    cout << Cory.GetSalary << endl;
    cout << Cory.GetyearsOfservice << endl;
         return 0;
      }
    and if u want the full list of errors, i'll post it in the next message!

    thanks for listening

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Posts
    122
    replace the "Cat" with "Employee" for each of the functions used in the class. And when you are calling some of the functions, you are passing parameters to them when it they have none.

  3. #3

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question waht do u mean, which functions am i doing this?

    hah i can't belive i put Cat insteed of employee, anyways..i fixed that, i still got 31 errors..and what do u mean what fucntions did i write which shoudln't have any paremeters passed ?

  4. #4
    Lively Member
    Join Date
    Jun 2000
    Posts
    122
    Sorry, I should have been more specific. In your code, you put...

    Code:
    Cory.GetyearsOfservice(4);
    but when you declared it, you didn't have any parameters.
    Also, you need to add a parenthesis at the end of every function. So replace...

    Code:
    cout << Cory.GetAge << endl;
    cout << Cory.GetSalary << endl;
    cout << Cory.GetyearsOfservice << endl;     
    return 0;
    with...

    Code:
    cout << Cory.GetAge() << endl;
    cout << Cory.GetSalary() << endl;
    cout << Cory.GetyearsOfservice() << endl;   
    return 0;

  5. #5

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking Hey thanks alot!

    thanks that and a typo of a variable fixed everything!

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In your .hpp file I would suggest putting some protection against multiple-inclusion into it, such as:
    Code:
    #ifndef __EMPLOYEE_HPP__
    #define __EMPLOYEE_HPP__
    
    // Code here
    
    #endif
    Otherwise if you include the file from two other source files the linker (I think) will choke
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width