|
-
Oct 10th, 2000, 01:01 PM
#1
Thread Starter
Frenzied Member
i get error that sayis 'Person' undelcared identifier
and aslo that left of all my functions/routines
that i "must have class/struct/union type"
anyone could help, would greatly appreciated it
Code:
#include <iostream>
using namespace std;
int main(void)
{
Person Kovan;
Kovan.SetName("Kovan");
Kovan.SetAge(20);
Kovan.SayAge();
Kovan.SayName();
Kovan.Greeting1();
Kovan.GoodBye();
int retval;
cin >> retval;
return retval;
}
class Person
{
public:
void SetName(char* chrName);
void SetAge(int Age);
char* GetName();
void Greeting1();
void SayName();
void GoodBye();
void SayAge();
private:
char* pName;
unsigned int pAge;
};
void Person::SetAge (int Age){
pAge = Age;
}
void Person::SetName(char* chrName)
{
pName = chrName;
}
char* Person::GetName()
{
return pName;
}
void Person::Greeting1()
{
cout << "hi there how are you doing?" << endl;
}
void Person::SayName()
{
cout << pName << endl;
}
void Person::GoodBye()
{
cout << "See Ya Later" << endl;
}
void Person::SayAge()
{
cout << pAge << endl;
}
-
Oct 10th, 2000, 01:29 PM
#2
Frenzied Member
Put the class and the functions before the main function.This works great.
Code:
#include <iostream>
using namespace std;
class Person
{
public:
void SetName(char* chrName);
void SetAge(int Age);
char* GetName();
void Greeting1();
void SayName();
void GoodBye();
void SayAge();
private:
char* pName;
unsigned int pAge;
};
void Person::SetAge (int Age){
pAge = Age;
}
void Person::SetName(char* chrName)
{
pName = chrName;
}
char* Person::GetName()
{
return pName;
}
void Person::Greeting1()
{
cout << "hi there how are you doing?" << endl;
}
void Person::SayName()
{
cout << pName << endl;
}
void Person::GoodBye()
{
cout << "See Ya Later" << endl;
}
void Person::SayAge()
{
cout << pAge << endl;
}
int main(int argc, char* argv[])
{
Person Kovan;
Kovan.SetName("Kovan");
Kovan.SetAge(20);
Kovan.SayAge();
Kovan.SayName();
Kovan.Greeting1();
Kovan.GoodBye();
int retval;
cin >> retval;
return retval;
}
-
Oct 10th, 2000, 01:39 PM
#3
Thread Starter
Frenzied Member
*bangs his head on the desk few times*
hehe
that really does make sense doesnt it?
what if i put all those functions and the class into a .H file..
if i use the #include..
will that automatically put them before main() or do i need to do somethign special?
becuase if i remember correctly i tried to put them in a file a while ago and i use to get same error..
thanks anyways for the help
i will try that out
-
Oct 10th, 2000, 01:50 PM
#4
Frenzied Member
Sticking the class definition in a header file is a pretty standard use for header files I think.
Harry.
"From one thing, know ten thousand things."
-
Oct 10th, 2000, 01:57 PM
#5
Monday Morning Lunatic
Although don't put the code into the header, split it into another .cpp file, as in:
-- Person.h --
Code:
#ifndef __PERSON_H__
#define __PERSON_H__
#include <iostream>
using namespace std;
class Person {
public:
void SetName(char* chrName);
void SetAge(int Age);
char* GetName();
void Greeting1();
void SayName();
void GoodBye();
void SayAge();
private:
char* pName;
unsigned int pAge;
};
#endif // __PERSON_H__
...and...
-- Person.cpp --
Code:
#include "Person.h"
void Person::SetAge (int Age) {
pAge = Age;
}
void Person::SetName(char* chrName) {
pName = chrName;
}
char* Person::GetName() {
return pName;
}
void Person::Greeting1() {
cout << "hi there how are you doing?" << endl;
}
void Person::SayName() {
cout << pName << endl;
}
void Person::GoodBye() {
cout << "See Ya Later" << endl;
}
void Person::SayAge() {
cout << pAge << endl;
}
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
-
Oct 10th, 2000, 01:57 PM
#6
Thread Starter
Frenzied Member
oopsie
my bad
i meant another .cpp
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
|