Hi, I am trying to access private level members with a Derived class but keep getting: Error1 cannot access private member declared in class 'TimeType'.
Here is my code for the Base Header file:
.
.
.
class TimeType
{
private:
int hours;
int minutes;
int seconds;

public:
virtual void setTime(int,int,int);
int gethours();
int getminutes();
int getseconds();
TimeType();
bool operator ==(const TimeType&);
bool operator <(const TimeType&);
friend ostream &operator <<(ostream &,const TimeType&);
friend istream &operator >>(istream &,const TimeType&);
};
.
.
.
...and here is my code for the Derived header file:
.
.
.
class extTimeType:public TimeType
{
private:
string timezone;
public:
extTimeType();
void setTimeZone(string);
void setTime(int,int,int,string);
string getTimeZone();
bool operator ==(const extTimeType&);
bool operator <(const extTimeType&);
friend ostream &operator <<(ostream &,const extTimeType&);
friend istream &operator >>(istream &,const extTimeType&);
};

extTimeType::extTimeType()
{
timezone="CPT"; 
}

ostream &operator <<(ostream &strm, const extTimeType &obj)
{
strm<<obj.hours <====ERROR HERE
<<":"<<obj.minutes <====ERROR HERE
<<":"<<obj.seconds <====ERROR HERE
<<":"<<obj.timezone;
return strm;
};

Any help appreciated.

In short, the private members of your base class should be declared as protected rather than private if you want derived objects to be able to access them directly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.