hestercybil
asked on
Make inherited protected to public
Is ther any way to make inherited protected members to public members?
Oh yes, you can use 'friend' to (effectively) make public a member function that had been declared 'protected', but that is not available for member variables.
-- Dan
-- Dan
Is this the sort of thing you are looking for.....?
class CA
{
protected:
int m_isVisible;
};
class CB : protected CA
{
public:
using CA::m_isVisible;
};
class CC
{
public:
void Method1();
};
void CC::Method1()
{
CB c;
c.m_isVisible = true;
}
class CA
{
protected:
int m_isVisible;
};
class CB : protected CA
{
public:
using CA::m_isVisible;
};
class CC
{
public:
void Method1();
};
void CC::Method1()
{
CB c;
c.m_isVisible = true;
}
Here's an idea: You can make a reference to a variable that looks and acts like that protected variable:
class Base {
public:
int nPub;
protected:
int nProt;
};
class Derived:public Base {
public:
Derived() : nProt(Base::nProt) { };
int& nProt;
};
void main() {
Derived oDerived;
oDerived.nProt= 1;
}
=-=-=-=-=-
If it quacks, it *is* a duck.
-- Dan
class Base {
public:
int nPub;
protected:
int nProt;
};
class Derived:public Base {
public:
Derived() : nProt(Base::nProt) { };
int& nProt;
};
void main() {
Derived oDerived;
oDerived.nProt= 1;
}
=-=-=-=-=-
If it quacks, it *is* a duck.
-- Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-- Dan