|
-
Jun 29th, 2001, 09:49 PM
#1
Thread Starter
Member
Basic Classes
Hi, It's me again. I have 3 more questions concerning classes.
1. I tried to make a simple program using class which would call functions to get information. Here's the code:
#include <iostream.h>
#include <stdlib.h>
class employee
{
public:
int age(int a); // defines employee;s age
int years(int yrs); // defines years worked
void speech(); // prints employee's speech
};
int employee::age(int a)
{
cout << "Enter a number.\n";
cin >> a;
return a; }
int employee::years(int yrs)
{
cout << "Enter anothe number.\n";
cin >> yrs;
return yrs; }
void employee::speech()
{
cout << "My name is Tom.\n";
}
int main()
{
employee tom;
tom.speech();
tom.age(int a);
tom.years(int yrs);
system("PAUSE");
return 0;
}
2. I read over and over about constructors and destructors in classes but I still don't get the point. What and when is something erased from memory?
3. Since I'm new to classes, what are they really for? Why can't I just use a function instead of grouping objects in a class? And what should the class return in a program?
Thank You!
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
|