In C++, is it possible to have a child class "hide" a base class' static fields and methods? (i.e. A has a field named ABC of type int, B:A and B has a field named ABC of type int)
+2
A:
Perhaps:
class B : private A
{
...
};
This will hide everything though, not just statics.
Andrew
2009-09-07 01:59:05
Missing ending semicolon. ;D
strager
2009-09-07 02:00:02
Fixed. Thanks, @strager.
Andrew
2009-09-07 02:36:59
+6
A:
#include <iostream>
using namespace std;
class A{
public:
static int a;
};
class B: public A{
public:
static int a; // hide base member
};
int A::a;
int B::a;
int main(){
A::a=10;
B::a=20;
B k;
cout << "\n" << B::a << k.a;
return 0;
}
adatapost
2009-09-07 02:03:04
Yes it will be hidden (but clients can still access the member of base class if they specify the base class name explicitly, for example `A::a`).
ChrisW
2009-09-07 02:38:40