Results 1 to 5 of 5

Thread: WHy am i getting tons of errors, like 81 of them (easy example gone bad)

  1. #1

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

    Question having troubles with simple class(a simple example blows up) heh

    hello everyone....
    i am having some problems making a simple class and setting its data members using accessor functions, i get tons of errors, whats wrong? i made all the methods inline, thats why i don't have like Employee::GetAge() {}
    here is the code for the .cpp file:
    Code:
    #include "Employee.hpp"
    
    
    int main() {
    
    Employee Cory;
    Cory.SetAge(15);
    Cory.SetSalary(100000);
    Cory.SetyearsOfservice(4);
    
    cout << Cory.GetAge << endl;
    cout << Cory.GetSalary << endl;
    cout << Cory.GetyearsOfService << endl;

    here is the code for the .hpp file:
    Code:
    #include <iostream.h>
    
    class Employee
    {
     public:
            void SetAge(int EAge) {age = EAge;}                     //inline
            void SetyearsOfService(int yOf) {yearsOfService = yOf;} //inline
            void SetSalary(int Money) {Salary = Money;}             //inline
    
            int GetAge() {return age;}                             //inline
            int GetyearsOfservice() {return yearsOfservice;}        //inline
            int GetSalary() {return Salary;}                        //inline
    
    
     private:
             int age;
             int yearsOfservice;
             int Salary;
    
     };

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You missed the last } off your main() function. Also, it needs to return a value (just stick return 0; at the end).
    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

  3. #3
    Guest
    Those are not inline functions.

    Code:
    inline int add(int one, int two) 
    {
        return one+two;
    }
    An inline function is when the function call is replaced with actual code when the program is compiled.

    If the function is small, and you are only calling it a few times, it can really speed up execution, but if you call it too many times, or the function is big, it will make your executable very large.

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Is it normal to give a header file the extension .hpp? I'm sure it will work just fine, but I've never seen it before.
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's all down to personal preference -- you can use any file as a header.

    Many C++ programmers use .cpp and .hpp to distinguish between .c and .h

    Anyway, struntz, what is the entire compiler output?
    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