redefine access label for an inherited function

Hello,

I am a bit confused here. In the following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class A {
private:
  virtual int getI() = 0;
};

class B: public A {
public:
  int getI() {return 30;}
};


int main(int argc, char** argv) {
  
  B b;
  cout << b.getI();
}


I am expecting that defining B::getI() for public access will cause problem. To my surprise, it compile and run correctly. Is it allowed to redefine the access label for an inherited function? Are there any restrictions?

Thanks,
wil.
Yes. Surprisingly, the access qualifiers (public, protected and private) control visibility and not access.
Hello kbw,

Thanks for the reply.

Can you elaborate a bit further? What is the difference between visibility and access?

wil.
Topic archived. No new replies allowed.