my inheritance class don't work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include "C:\Users\Isaac Dixon\Documents\School\Oak Wood University\c++ data structchers\class HW\theAdress.h"
using namespace std;

class Person: public Adress {
protected:
int homeNumber,dd,mm,yy,phoneNumber;
string name;
  public:
void setHomeNumber (int a){
	homeNumber=a;
}
void setDateOfBirth(int a, int b, int c){
	dd=a;
	mm=b;
	yy=c;
}
void setName(string a){
	name=a;
}
	
//};
int getHomeNumber(){
        return homeNumber;
	}
int getDateOfBirth(){
	return dd;
	return mm;
	return yy;
}
string getName(){
	getline(cin, name);
	return name;
}
};
 
Last edited on
You have declared some of the functions outside the class.
thanks but I still have one more Error
it says"
[Error] expected class-name before '{' token".
I don't see where Adress is defined.
I thought the inherited class Address would not need to be defined

I'm prity sure there's something about inheritance that I'm not understanding

how exactly would you define it?
The class need to be defined before you can inherit from it. If you have the Address class defined in a header file you can include that header before you define Person.

I'm not really sure why you use inheritance here though. Think about it. Is a person really an address? If you want a person to have an address you should probably use member variable(s) instead (maybe that's what homeNumber and phoneNumber is for?).
@isaacthebro

Just wondering, could we ask you not to start a new topic if the subject is the same? Just keep the original one going.

Now we have Peter87 spending time & effort in giving the same advice as what was given in the other topic.

I am not trying to be hardcore or anything, more of a gentle suggestion :+). It's just a little irritating to those who reply to a lot of topics in order to help. It happened again to me last week - I did a big long reply, only to discover that the same things had been said the day before. I didn't notice the previous post because it would have been on page 2 or 3 in the forum.


http://www.cplusplus.com/forum/general/157691/#msg807837
There is no class called Adress, you are inheriting from an imaginary class that you've created in your head that isn't really there. You need to define and declare the "Adress" class you want to inherit from...
Last edited on
THERE NOT THE SAME TheIdeasMan there different classes, but they do have the same name

sorry next time ill put different class names and put them on the same form
I honestly didn't think of doing that



thank you so much for your help Peter87
Last edited on
But idea of the two posts is the same isn't it?

And Peter87 gave the exact same advice as what I gave you in the other topic.

My other advice was if you want to practice inheritance, then choose an example that requires inheritance.

Did you read this part?

TheideasMan wrote:
I am not trying to be hardcore or anything, more of a gentle suggestion :+). It's just a little irritating to those who reply to a lot of topics in order to help. It happened again to me last week - I did a big long reply, only to discover that the same things had been said the day before. I didn't notice the previous post because it would have been on page 2 or 3 in the forum.


Sorry I am a bit tired, I don't mean this to be brutal, just a gentle suggestion :+)
yes they have the same idea but they still had some different problems I was trying to learn, but at the same time there was some problems that were the same.

never the less, I understand what your saying, ill try not to do that. Sorry and thanks for the suggestion.
Topic archived. No new replies allowed.