|
-
Feb 10th, 2001, 04:33 PM
#1
Thread Starter
Registered User
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;
};
-
Feb 10th, 2001, 04:39 PM
#2
Monday Morning Lunatic
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
-
Feb 10th, 2001, 06:35 PM
#3
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.
-
Feb 10th, 2001, 06:40 PM
#4
Frenzied Member
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."
-
Feb 10th, 2001, 06:43 PM
#5
Monday Morning Lunatic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|