Kindly assist. I would like to create class A and inherit datetype functions. to be able to call out like.
A parent;
A.Date.SetDay... //something like dat. Anyone who knows how. Kindly guide.
class A{
public:
//get and set method of class date
void SetDate(DateType date) {m_date = date;}
DateType GetDate() {return m_date;}
private:
//refers to the date
DateType m_date;
};
class DateType{
public :
//get and set method of variable day
void SetDay(short day) {m_day = day;}
short GetDay() {return m_day;}
private : ---- members not included-----
};
it returns a pointer to the private m_date inside the A class.
to access object pointer elements use '->', that is why i used that.
It is done this way, because otherwise there is no way to alter a private element outside a object.
But using it this way has the same effect as editing a public element.
So maybe that is a better way, make m_date public.
You could also make a member function that takes in a day and set it to the private m_date.
But then i would advise you to use the inhertance example i gave you in my first post.
What is the point of having a private member variable if you have a public member function that returns a non-const pointer to it, thus giving full public access to it? This is wrong on so many levels.