access protected menbers in derived classes

I'm sorry, guys if i cann't post my code it's written in my language, but the problem looks like this i have 5 classes, two base and the others derive those two, CPark, derives from CFloor, and this one derives from CPlaces, that derive CData and Ctax... Let write a simple code;

class CData:
{

protected:
int year;
int month;
public:
//methods to use these members
};

class CTax:
{
protected:
int cents;
int euros;
public:
CData(int year,int month);
//methods to use these members
};
class CPlaces: public CData, CTax
{
public:
CPlaces *Array_Places[6];
CData *date;
};

class CFloor: public CPlaces, CData, CTax
{
public:
CFloor *Array_Floors[4];
};

/*
I can save the data using the pointers like
in a method of CPark*/

void CPark::Insert_Car()
{
int Year;;
int Month;
cin >> Year;
cin >> Month;

Array_Floors[0]->Array->Places[0]->date=new CData(Year,Month;
}

/*but if i want to access them to eco in the screen i can't access menbers of CData i know that if they're declared as public i can access them but i want to keep them protected to do this.*/

void CPark::showonscreen()
{
//Like this i can't access menber year.
cout << Array_Floors[0]->Array->Places[0]->date->Year;
//Like this i need a class tipe specifier on Array_Floors
cout << Array_Floors[0]->Array->Places[0]->date.Year;
}

Somebody there help me i want to keep the menbers in CData protected...
If you want to keep the members protected then you need to create access (get/set) functions and make them public. Something like:

int CData::getYear() { return year; }

then call like:

Array_Floors[0]->Array->Places[0]->date.getYear();

would this help?
I'm not entirely sure what you want to do especially since im reading it black on white which hurts my eyes a lot, so all i really know is that you want access rights to something... I think you want to use friend (unless i misinterpreted your question). That way ONLY CPark::showonscreen() and others that you shared access with will have access to the members. In other words, it stays protected but adds an exception.

here's a link about it
http://www.cplusplus.com/doc/tutorial/inheritance/
Last edited on
If you want to keep the members protected then you need to create access (get/set) functions and make them public
¿What would be the difference with making the variables public in the first place?

@OP: Your class relations are weird.
¿A place is a data? ¿and it is aware of other places?
¿What do you want to do?

Also, please provide the CPark declaration
Topic archived. No new replies allowed.