P
Paul Bibbings
This is just an observation (of my own ignorance, really). I have many
times used a class-scope using declaration to `promote' the
accessibility of a member of a base class in a derived class, but I
hadn't ever applied it to do the opposite, i.e. hide a base class
member. Consequently, though I had no reason to suppose that it wasn't
possible, I did have to try it out (`engineer's solution' - no access to
the Standard at this moment) and found that it does work.
#include <iostream>
class A {
private:
int i_;
public:
A(int i) : i_(i) { }
void seti(int i) { i_ = i; }
int geti() const { return i_; }
};
class B : public A {
public:
B(int i) : A(i) { }
void dbli() { seti(2 * geti()); }
private:
using A::seti; // hide
};
int main()
{
A a1(1);
a1.seti(2);
std::cout << "a1.geti() = " << a1.geti() << '\n';
B b1(3);
// b1.seti(4); // inaccessible
b1.dbli();
std::cout << "b1.geti() = " << b1.geti() << '\n';
}
/**
* Output: // largely irrelevant
* a1.geti() = 2
* b1.geti() = 6
*/
So... Yay!
Regards
Paul Bibbings
times used a class-scope using declaration to `promote' the
accessibility of a member of a base class in a derived class, but I
hadn't ever applied it to do the opposite, i.e. hide a base class
member. Consequently, though I had no reason to suppose that it wasn't
possible, I did have to try it out (`engineer's solution' - no access to
the Standard at this moment) and found that it does work.
#include <iostream>
class A {
private:
int i_;
public:
A(int i) : i_(i) { }
void seti(int i) { i_ = i; }
int geti() const { return i_; }
};
class B : public A {
public:
B(int i) : A(i) { }
void dbli() { seti(2 * geti()); }
private:
using A::seti; // hide
};
int main()
{
A a1(1);
a1.seti(2);
std::cout << "a1.geti() = " << a1.geti() << '\n';
B b1(3);
// b1.seti(4); // inaccessible
b1.dbli();
std::cout << "b1.geti() = " << b1.geti() << '\n';
}
/**
* Output: // largely irrelevant
* a1.geti() = 2
* b1.geti() = 6
*/
So... Yay!
Regards
Paul Bibbings