get value from class to another class

hi, i'm trying to get the value from a variable in a class to storage in a inherited class. some reason(my lack knowledge) the input is 0. any hints? thanks

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//header file
#ifndef _patient_H
#define _patient_H
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;
class patient
{
private:


public:	
	
string  dAdmited="12/09/13";
string dDischarg "12/09/13";
string pDOB "12/09/93";
};

  class dateType : public patient
{
private:
string  date;
string date ;
string patient ;
public:
virtual void setDate();
dateType();
};
#endif 


//cpp file
#include "stdafx.h"
# include "patient.h"

date :: date ()
{

}
 void date :: Date()//)is this correct?
{
	  patientDOB = patientType:: patient ;
	 dateAdmited = patientType:: date  ; 
	  dateDischarg= patientType::date  ;
	cout <<"Patient : " << patient  << " " <<"\n"<<"Patient   "
            << dateAdmited <<" "<<"\n"<<"Patient   "<<     date <<" "<<"\n";
}

Last edited on
Usually a child class is more descriptive that a parent. For example a parent class could be Pizza and a child could be ThreeMeatPizza or DeepDishPizza. You might also want to look at the CPolygon example here: http://www.cplusplus.com/doc/tutorial/inheritance/

Basically what I am wanting to say is that it looks like you are not using inheritance the way it is meant to be used. You have variables that are already in the parent class also located in the child class. And in my opinion DateType is not a more descriptive form of a Patient. Something like ChildPatient or OldPatient would be a better child candidate.
http://www.cplusplus.com/doc/tutorial/inheritance/
I suggest you re-read the above document for a better understanding of inheritance. Basically, since dateType publicly inherits from patient, a dateType object will have the fields dAdmited, dDischarg, and pDOB with the values you entered.

Also, why is setAllDate() virtual? Are you planning on having subclasses inheriting from the dateType class?

As well, setAllDate should probably take in an argument. I'm assuming you want to pass your dateType object some dates.

Last edited on
thanks :~)
Topic archived. No new replies allowed.