Hi to all,can u tell me,suppose i have a class in private section i declar a int p,then i derived another class there also i have a private data int p with same name so how can access that data as both in base and derived clas both have same name,,,,,,how can i differentita two data
First thing to do is change one of the names. If you can't do that then...
1 2 3 4 5 6 7 8 9 10 11 12
void derived_class::my_func(void)
{
base_class::p = 1; // OK - references base class variable
p = 2; // OK - references derived_class variable by default or ...
derived_class::p = 2; // OK - explicitly references derived_class variable
}
void base_class::my_func2(void)
{
derived_class::p = 1; // Not allowed to reference derived members from base class
p = 1; // OK - references base_class variable only
}
class parent
{
private:
// this is my stuff. everyone else: access denied.
protected:
// this is stuff I'm willing to share with the family,
// but not strangers.
public:
// this is what everyone can see of me.
};
class child: public parent
{
private:
// my private stuff. I don't know what Dad's private stuff is.
protected:
// family stuff I got from Dad.
public:
// etc.
};
I think it is worth your time to spend a bit over at the C++FAQ-Lite and read through the sections on inheritance http://www.parashift.com/c++-faq-lite/